Pointer to class error

Hi, I have an error and it says: expression must be a pointer type to class

Here's my node class
class node (node.h)
{
public:
node* pNext;
citizen* pData;
node();
node(int NAS,string name, string DDN);
void displayC();
};
---------------------------------------
class citizen: public node (citizen.h)
{
int NAS;
string name;
string DDN;
public:
citizen(int n);
citizen(int N ,string n ,string D);
void displayC();
};
---------------------------------------
citizen::citizen(int N, string n, string D) (citizen.cpp)
{
NAS = N;
nom = n;
DDN = D;
}

void citizen::displayC()
{
cout <<"NAS : " << NAS << " Name: " << name << " Date de naissance : " << DDN << endl;
}

---------------------------------------
Here's what I have in node.cpp
node::node()
{
pNext = NULL;
}

void node::displayC()
{
pData->displayC(); <<<<<<------ error right here
}
You'll have to provide an actual listing so we can see what include files are pulled in from node.cpp.
Sorry, I don't get it, what do you mean by an actual listing?
I meant the source code listing of node.cpp.
does your node class "know" about your citizen class?
Have you forward declared or hash-included it?
Your "node" class should know what are the methods provided in "citizen" to allow you to call any of its methods. So mere forward declaration wont work. You have to include "citizen.h" in "node.h" file.

BTW, the design which you have is a bad one. You are storing a pointer to a child object in Parent class. Why is that?
Last edited on
File node.cpp shall include header citizen.h that to know the definition of the class. Otherwise it does not know what is displayC() and how it is defined.
Topic archived. No new replies allowed.