Error C2504: "BASECLASS": base class undefined

I checked a message like this, but the connection was different, the problem was not resolved. The problem with mine is that for some reason the linker expects there to be a definition for the base class, but the base class is just an interface. The following is a general error

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 connect to each other

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 the GxRenderManager, there are GXRenderer, windows, GXDX, GXGL headers. I guess by including them all in this document. they are all linked together, as if they were all in the same document. correct me if I am mistaken, as the title of the header. 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 what is going on. I think that how I link documents, I am not sure.

+6
c ++ c visual-studio-2008 visual-c ++ visual-studio
source share
3 answers

Problem: you need to have #include "GXRenderer.h" at the top of both: GXGL.h, as well as GXDX.h.

A base type must be defined not only to define a derived type.

By the way, an error is a compilation error that is not related to an error.

Edit: about overriding class type:

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

The #pragma once indicates that the file will be included no more than once by the compiler in the assembly.

+4
source share

You have included them all in GXRenderManager.h , which means that GXRenderManager.h is fine.

But you forgot to include them all in GXGL.cpp and GXDX.cpp . In these .cpp files, the GXRenderer class GXRenderer completely unknown.

There are at least two โ€œschoolsโ€ of #include strategies. One says that the header file should include everything that is needed for its own compilation. This would mean that GXGL.h and GXDX.h should include GXRenderer.h . If you followed this strategy, your GXGL.cpp and GXDX.cpp would be in order, as it is now.

Another "school" says that the header files should not include each other at all, i.e. all inclusions must be done through .cpp files. At first glance, you can assume that your GXGL.h and GXDX.h follow this strategy (since you donโ€™t invest anything in them), but then your GXRenderManager.h looks completely different.

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

+2
source share

I got error C2504: "CView": the base class is undefined where CView is not directly my base class from which I inherit.

I inherit mYClass from MScrollView, "on this subject any class that is not a base class, here's what to note here" but bug C2504. When I included it in the header where this problem occurs, this problem is resolved.

 #include "stdafx.h" 

where stdafx.h has #include, which contains the entire base class defined ... hope this answer resolves everyone who runs into this problem.

+1
source share

All Articles