I’m starting to use C++ and I have some problems I hope you people can help me.
I have the following classes on their own file.
Code:
/**
* Basic application class.
* Any application needs this.
*/
class App
{
public:
~App(); /**< Destructor. */
int init(); /**< Application initiation. */
void checkExtensions(); /**< Check that required extensions are available. */
void idle(); /**< Function called every frame. */
void render(); /**< Render basic info, etc. */
void keyPress(int key); /**< Check if a valid key was pressed. */
};
Code:
/**
* Class that deals with Win32 specific stuff.
* This includes mouse handling, basic loop, window creation, etc.
*/
class WinApp
{
public:
WinApp(); /**< Constructor. */
~WinApp(); /**< Destructor. */
int setVideoMode(int width, int height, int fs = 0); /**< Set the video mode for the application. */
void setTitle(const char *title); /**< Set the title of the window. */
void checkExtension(const char *extension); /**< Check if a needed extension is available. */
void error(); /**< Check if there was any error. */
void main(); /**< Deal with Window's messages, main loop. */
int windowWidth; /**< Width of the window. */
int windowHeight; /**< Height of the window. */
int fullScreen; /**< Fullscreen. */
char title[1024]; /**< Title of the window. */
int mouseX; /**< Location of the mouse pointer along the X axis. */
int mouseY; /**< Location of the mouse pointer along the Y axis. */
int mouseButton; /**< Check what mouse button was pressed. */
float fps; /**< Frames per second. */
};
The application needs just one instance of App and one instance of WinApp. And that single instance of WinApp needs to be inside my single instance of App in such way that there is no WinApp without App, and in such way that WinApp can call functions of App. How do I do that without using inheritance? I was using inheritance and I didn’t have any problem but it was blending everything too much, making it WinApp more of a part of App and not some “service module” which is what I want.