Link to home
Start Free TrialLog in
Avatar of cuziyq
cuziyq

asked on

Visual C++ error: Base Class Undefined

This is a DLL project.  I am writing a class called CDGpanel, which inherits from CDGbase.  The compiler keeps telling me that the base class is undefined despite the fact that the base class is #included properly and compiles just fine.  With the derived class commented out, I can even instantiate the base class, so I know there's nothing wrong with it.  I have even tried to forward declare the base class in the derived class's header, but that doesn't seem to make any difference.  This is the first class I've tried to inherit, so I assume this will be a problem for any others I attempt to write.  Neither the base class nor the derived class do anything at the moment because all I've done is stub the constructors/destructors.

I have pasted the code below.  Note that the base class has no default constructor.  This is intentional.  When this project takes its final form, CDGbase will be a pure abstract class whose constructor will be called explicitly from its derived classes.  I don't know if this makes a difference or not.

One other thing that I am sure is related . . . Every class I write that depends on another class I have written, #including it doesn't seem to be enough.  I have to put a forward declaration in there for it to compile.  Also, I have typedef'd std::string to simply String, but I have to typedef it for every single class in which it's used.

Any ideas?
#pragma once
 
#include "Controller.h"
 
#define SPEC_ID unsigned long
 
typedef std::string DGLIB_API String
 
class DGLIB_API CDGpanel :public CDGbase
{
public:
	CDGpanel(SPEC_ID spec, CDGbase *owner, String *title, int x, int y, int width, int height);
	virtual ~CDGpanel();
};
 
CDGpanel::CDGpanel(STYLE style, CDGbase *owner, String *title, int x, int y, int width, int height)
	:CDGbase(owner, title, x, y, width, height)
{
}
 
CDGpanel::~CDGpanel()
{
}

Open in new window

Avatar of alb66
alb66
Flag of Italy image

Can you post the code of "controller.h" ?
CDGpanel's constructor have a different type for the 1st parameter in declaration and implementation: SPEC_ID vs STYLE
Avatar of cuziyq
cuziyq

ASKER

>> Can you post the code of "controller.h" ?
Controller.h is just a bunch of typedefs, #defines, and #includes.  It contains no code.

>>CDGpanel's constructor have a different type for the 1st parameter in declaration and implementation: SPEC_ID vs STYLE
That was just my mistake from trying to play around with different things in an attempt to make it work.  The compiler griped about that and I fixed it, but I didn't realize I had pasted it into this post.  This first parameter is supposed to be SPEC_ID spec.  It's now the same in both files.
>> Controller.h is just a bunch of typedefs, #defines, and #includes.  It contains no code.

Ok, and where is the declaration of CDGbase?
Avatar of cuziyq

ASKER

CDGbase.h is #included from Controller.h

It's definition is as follows:
#pragma once
 
#include "Controller.h"
 
typedef std::string DGLIB_API String
 
class DGLIB_API CDGbase
{
public:
         CDGbase(CDGbase *owner, String *title, int x, int y, int width, int height);
         virtual ~CDGbase();
};
 
CDGbase::CDGbase(CDGbase *owner, String *title, int x, int y, int width, int height)
{
}
 
CDGbase::~CDGbase()
{
}

Open in new window

Avatar of cuziyq

ASKER

Here is Controller.h, by the way:
#pragma once
#pragma comment(lib,"gdiplus.lib")
 
#ifdef DGLIB_EXPORTS
#define DGLIB_API __declspec(dllexport)
#else
#define DGLIB_API __declspec(dllimport)
#endif
 
#include <string>
#include <windows.h>
#include <gdiplus.h>
#include "DGapplication.h"
#include "DGeasel.h"
#include "DGbase.h"
#include "DGpanel.h"
 
typedef std::string DGLIB_API String;

Open in new window

In DGpanel.h you should try to include CDGbase.h instead of Controller.h.
Avatar of cuziyq

ASKER

Just tried it.  Didn't work.  Still says the base class is undefined.

I also tried scoping the inheritance as well:
class DGLIB_API DGpanel :public ::GDbase

That didn't work either :-(
Can you post also the code where you allocate the object and #include statement in that file?
Avatar of cuziyq

ASKER

Sure.

The project in which these classes are located is a DLL.  None of them get instantiated by one another.  The DLL is going to be an SDK for one of my company's products, so when it gets distributed it's just going to be a .DLL file and a precompiled header (which is what Controller.h is for).

To test if my skeleton library is working, I simply created a seperate Win32 project as follows.

The DGlib.h file just contains what Visual Studio provided for me (the DLLMain function, which at this point does nothing).  DGLib.h just #includes Controller.h, which functions just like stdafx.h would.

All of this seems to work just fine, because the code below compiles and runs.

In fact, the test project listed below hasn't changed.  All I am trying to do is make an additional class (within the DG Library) called DGpanel that inherits from DGbase (which will ultimately be an abstract class, but it's not right now).  But I can't get that far because simply declaring the inheritance causes the compiler to swear that DGbase is not defined.  Obviously, it is because everything works as long as I don't try to inherit.  Maybe there's something wrong with the order in which things are being compiled?
#include <windows.h>
#include "DGLib.h"
 
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
     DGbase *test1 = new DGbase(NULL, "Test", 0, 0, 640, 480);
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of cuziyq
cuziyq

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial