Say I have three window classes, one for each OS I want to support:
- WindowsWindow
- OSXWindow
- LinuxWindow
They all inherit from the Window class. This is also the class you instantiate. The Window class have the . -> and :: operators overloaded, and depending on which OS were running on (based on IFDEFs) it casts the this pointer to the relevant class.
What I want to do is just create a Window instance without any clue as to what OS is running. Is this thinking very wrong? Is the downcast to dangerous? Are there better ways to do this?
Im aware that there are libraries to do this, but I want to try it myself.
I guess the easiest way is to create a factory. But can something like this be done?