Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1510
  • Last Modified:

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

0
cuziyq
Asked:
cuziyq
  • 6
  • 5
1 Solution
 
alb66Commented:
Can you post the code of "controller.h" ?
0
 
alb66Commented:
CDGpanel's constructor have a different type for the 1st parameter in declaration and implementation: SPEC_ID vs STYLE
0
 
cuziyqAuthor Commented:
>> 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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
alb66Commented:
>> Controller.h is just a bunch of typedefs, #defines, and #includes.  It contains no code.

Ok, and where is the declaration of CDGbase?
0
 
cuziyqAuthor Commented:
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

0
 
cuziyqAuthor Commented:
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

0
 
alb66Commented:
In DGpanel.h you should try to include CDGbase.h instead of Controller.h.
0
 
cuziyqAuthor Commented:
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 :-(
0
 
alb66Commented:
Can you post also the code where you allocate the object and #include statement in that file?
0
 
cuziyqAuthor Commented:
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

0
 
cuziyqAuthor Commented:
Nevermind.  I figured it out.  For some reason, the order of my #includes in Controller.h makes all the difference.  I changed it and now it works.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now