Let's assume you're building a game and you want to have a Window class which it's implementation differs on different platforms.
I have seen two ways to achieve this. One is by wrapping each implementation with preprocessing directives and the second by using interfaces.
For example:
And the second way:Code:#ifdef Windows #include <Windows.h> class Window { //Windows specific code. }; #endif #ifdef Linux #include <Linux.h> class Window { //Linux specific code. }; #endif
Which one should I use?Code://Window.h class Window { public: virtual void CreateWindow() = 0; . . . } //WindowsWindow.h class WindowsWindow: public Window { //Windows specific implementation. public: virtual void CreateWindow() { } . . . } //LinuxWindow.h class LinuxWindow: public Window { //Linux Specific implementation. public: virtual void CreateWindow() { } . . . }





Reply With Quote
