ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The problem is that BaseClass is only a forward declaration. Base classes must be completely declared types (or otherwise the calculations to figure out the size of the derived type wouldn't work, among other things).
#include <iostream>
using namespace std;
class BaseClass
{
protected:
int number;
public:
BaseClass(int num = 1){number = num;}
int num () {return number;}
};
DerivedClass.h
Code:
using namespace std;
#include "BaseClass.h"
class DerivedClass : public BaseClass
{
public:
DerivedClass(int num = 1){}
void setNum (int num = 1){number = num;}
};
However if you remove the #include from DerivedClass.h as follows:
Code:
using namespace std;
//#include "BaseClass.h"
class DerivedClass : public BaseClass
{
public:
DerivedClass(int num = 1){}
void setNum (int num = 1){number = num;}
};
Then you get the following compile errors:
Code:
2 main.cpp In file included from main.cpp
6 DerivedClass.h expected class-name before '{' token
DerivedClass.h In member function `void DerivedClass::setNum(int)':
9 DerivedClass.h `number' undeclared (first use this function)
... plus many more relating to main.cpp
So are you setting up and using header files correctly?
Yup, I've confirmed, and then reconfirmed that all the header files are being included and stuff. But I still can't figure out the problem. I'll get back to you guys with some code.
Then maybe your configure guard is messed up? The #define it keys off of has to be unique, and sometimes one forgets to change that if you copy-and-hack from another file.
I'm sorry? I didn't get that. Could you please elaborate? And I've stripped the code as much as I could. How do I give it to you guys? It's still too much to post here.
I'm sorry? I didn't get that. Could you please elaborate? And I've stripped the code as much as I could. How do I give it to you guys? It's still too much to post here.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.