Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
// Interfaceklasse / Abstract class iGFXInterface { public: virtual void drawTriangle() = 0; }; // SDL Klasse class cSDLEngine: public iGFXInterface { public: inline virtual void drawTriangle(){ cout << "SDL::drawTriangle()" << endl; } }; // OpenGL Klasse class cOGLEngine: public iGFXInterface { public: inline virtual void drawTriangle(){ cout << "OGL::drawTriangle()" << endl; } }; // Grafik Engine template <class __T> class GFXEngine : public __T { }; |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
int main(int argc, char *argv[]) { GFXEngine<cSDLEngine> *Engine1 = new GFXEngine<cSDLEngine>(); GFXEngine<cOGLEngine> *Engine2 = new GFXEngine<cOGLEngine>(); Engine1->drawTriangle(); Engine2->drawTriangle(); _getch(); delete Engine1; delete Engine2; return 0; } |
C-/C++-Quelltext |
|
1 2 3 |
GFXEngine *Engine1 = new GFXEngine<cSDLEngine>(); // oder so GFXEngine *Engine1 = new GFXEngine( cSDLEngine ); |
Anonymous
unregistriert
C-/C++-Quelltext |
|
1 2 |
iGFXEngine *Engine1 = new cSDLEngine; iGFXEngine *Engine1 = new cOGLEngine; |
C-/C++-Quelltext |
|
1 2 |
iGFXInterface *Engine1 = new cSDLEngine; iGFXInterface *Engine1 = new cOGLEngine; |
Anonymous
unregistriert
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
// Interfaces für Graphics. namespace graphics { // Mögliche Typen. enum device_type { sdl, opengl, direct3d } // Basis-Klasse für Devices. class device { // [...] virtual texture* create_texture (...) = 0; // [...] }; // Basis-Klasse für Texturen. class texture { // [...] }; } // [...] // Implementierungen. namespace graphics { namespace impl { class sdl : public graphics::device { // [...] }; class opengl : public graphics::device { // [...] }; class direct3d : public graphics::device { // [...] }; } } // Device erstellen. graphics::device* create_device (graphics::device_type type) { switch (type) { // SDL-Implementierung ist angefordert. case graphics::device_type::sdl: return new (graphics::impl::sdl ()); // OpenGL-Implementierung ist angefordert. case graphics::device_type::opengl: return new (graphics::impl::opengl ()); // Direct3D-Implementierung ist angefordert. case graphics::device_type::direct3d: return new (graphics::impl::direct3d ()); } return (nullptr); } // OpenGL-Device erstellen. graphics::device* device = create_device (graphics::device_type::opengl); // Textur erstellen. graphics::texture* texture = device->create_texture (...); |
Zitat von »"King"«
Das ist ein Copy&Paste Problem und leider nicht ganz richtig. Ersetze iGFXEngine durch iGFXInterface:
C-/C++-Quelltext
1 2 iGFXInterface *Engine1 = new cSDLEngine; iGFXInterface *Engine1 = new cOGLEngine;
Werbeanzeige