Solved

Visual C++ error:  Base Class Undefined

Posted on 2008-06-16
11
1,421 Views
Last Modified: 2013-12-14
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
Comment
Question by:cuziyq
  • 6
  • 5
11 Comments
 
LVL 19

Expert Comment

by:alb66
Comment Utility
Can you post the code of "controller.h" ?
0
 
LVL 19

Expert Comment

by:alb66
Comment Utility
CDGpanel's constructor have a different type for the 1st parameter in declaration and implementation: SPEC_ID vs STYLE
0
 
LVL 14

Author Comment

by:cuziyq
Comment Utility
>> 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
 
LVL 19

Expert Comment

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

Ok, and where is the declaration of CDGbase?
0
 
LVL 14

Author Comment

by:cuziyq
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 14

Author Comment

by:cuziyq
Comment Utility
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
 
LVL 19

Expert Comment

by:alb66
Comment Utility
In DGpanel.h you should try to include CDGbase.h instead of Controller.h.
0
 
LVL 14

Author Comment

by:cuziyq
Comment Utility
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
 
LVL 19

Expert Comment

by:alb66
Comment Utility
Can you post also the code where you allocate the object and #include statement in that file?
0
 
LVL 14

Author Comment

by:cuziyq
Comment Utility
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
 
LVL 14

Accepted Solution

by:
cuziyq earned 0 total points
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now