Original Post
Hi, while working on my component system for my engine, I've found a little problem related to interfaces & implementations. In this sample I have 2 interfaces & 2 implementations: IMesh -> CMesh ILODMesh -> CLODMesh. CLODMesh IS also a CMesh, so in the "interface side", ILODMesh SHOULD be derived from IMesh. Take a look at the sample code (actually working code):
class IMesh
{
public:
virtual int GetVertexCount() = 0;
};
class CMesh : public IMesh
{
public:
int GetVertexCount() { return 50; }
};
class ILODMesh : public CMesh
{
public:
virtual int GetCurrLODLevel() = 0;
};
class CLODMesh : public ILODMesh
{
public:
int GetCurrLODLevel() { return 3; }
};
Now I can use these 2 classes like this:
IMesh * mesh = new CMesh;
ILODMesh * lodmesh = new CLODMesh;
What I want to do, is to HIDE the implementation headers (CMesh.h, CLODMesh.h), the user will only have the interface headers (IMesh.h , ILODMesh.h). The factory system is responsible for returning new CMesh or new CLODMesh. Now the problem is THIS line ---> class ILODMesh : public CMesh what I really want to do is something like this: class ILODMesh : public IMesh so the ILODMesh.h doesn't have to know anything about the CMesh implementation. There is nothing wrong with that line, BUT the problem comes when I want to IMPLEMENT CLODMesh using both: the ILODMesh interface and the CMesh implementation. I've tried the following without luck: class CLODMesh : public ILODMesh, public CMesh the compiler complains: 'CLodMesh' : cannot instantiate abstract class Do you think there is a way to keep implementations on one side and interfaces in the other and create this kind of hierarchical relationships? At the moment my solution was the sample code above, creating ILODMesh from public CMesh, but the client will require cmesh.h... What do you think guys...