Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error C2504: 'BASECLASS' : base class undefined

I checked out a post similar to this but the linkage was different the issue was never resolved. The problem with mine is that for some reason the linker is expecting there to be a definition for the base class, but the base class is just a interface. Below is the error in it's entirety

c:\users\numerical25\desktop\intro todirectx\godfiles\gxrendermanager\gxrendermanager\gxrendermanager\gxdx.h(2) : error C2504: 'GXRenderer' : base class undefined

Below is the code that shows how the headers link with one another

GXRenderManager.h

#ifndef GXRM
#define GXRM
#include <windows.h>
#include "GXRenderer.h"
#include "GXDX.h"
#include "GXGL.h"

enum GXDEVICE {
    DIRECTX,
    OPENGL
};

class GXRenderManager {
public:
    static int Ignite(GXDEVICE);

private:
    static GXRenderer *renderDevice;

};

#endif

at the top of GxRenderManager, there is GXRenderer , windows, GXDX, GXGL headers. I am assuming by including them all in this document. they all link to one another as if they were all in the same document. correct me if I am wrong cause that's how a view headers. Moving on...

GXRenderer.h

class GXRenderer {

public:
    virtual void Render() = 0;
    virtual void StartUp() = 0;

};

GXGL.h

class GXGL: public GXRenderer {

public:
    void Render();
    void StartUp();
};

GXDX.h

class GXDX: public GXRenderer {
public:
    void Render();
    void StartUp();
};

GXGL.cpp and GXDX.cpp respectively

#include "GXGL.h"

void GXGL::Render()
{

}

void GXGL::StartUp()
{

}

//...Next document

#include "GXDX.h"


void GXDX::Render()
{

}

void GXDX::StartUp()
{

}

Not sure whats going on. I think its how I am linking the documents, I am not sure.

like image 713
numerical25 Avatar asked Jun 16 '10 13:06

numerical25


2 Answers

The problem is You need to have #include "GXRenderer.h" at the top of both: GXGL.h and also GXDX.h.

The base type must be defined not just declared before defining a derived type.

By the way, the error is a compiling error not linking error.

Edit: About your class type redefinition:

at the top of every header file you should have #pragma once.

The #pragma once directive specifies that the file will be included at most once by the compiler in a build.

like image 79
Brian R. Bondy Avatar answered Sep 30 '22 18:09

Brian R. Bondy


You included them all into GXRenderManager.h, meaning that GXRenderManager.h is OK.

But you forgot to include them all into GXGL.cpp and GXDX.cpp. In these .cpp files GXRenderer class is completely unknown.

There are at least two "schools" of #include strategies. One says that header file must include everything that is needed for its own compilation. That would mean that GXGL.h and GXDX.h must include GXRenderer.h. If you followed that strategy, your GXGL.cpp and GXDX.cpp would be OK as they are now.

Another "school" says that header files must not include each other at all, i.e. all inclusions must be done through .cpp files. At first sight one could guess that your GXGL.h and GXDX.h follow that strategy (since you are not including anything into them), but then your GXRenderManager.h looks completely different.

You need to decide which strategy you are trying to follow and follow it. I'd recommend the first one.

like image 31
AnT Avatar answered Sep 30 '22 18:09

AnT