The code below fails to instantiate the Display_OpenGL class, because it does not consider the Surface implementation from Surface_OpenGL to map with the Display : Surface class.
Uncommenting this line fix the problem but then this is not elegant. //void Draw() { Surface_OpenGL::Draw(); }
Is there's a better solution for what I want to do? Draw is already defined in Surface_OpenGL, but it seems like it needs to be defined explicitly for Display as well, any nice solutions?
Thank you.
class Surface
{
public:
virtual void Draw() = 0;
};
class Display : public Surface
{
};
class Surface_OpenGL : public Surface
{
public:
void Draw(){}
};
class Display_OpenGL : public Display, public Surface_OpenGL
{
public:
//void Draw() { Surface_OpenGL::Draw(); }
};
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
//Error cannot instantiate abstract class
Display *display = new Display_OpenGL();
display->Draw();
delete display;
return 0;
}