I’m trying to define an array of type Class, for my homework. The classB and classC is defined inside another classA, and I have to define the an Array which
is defined inside classC of type classB. Below is the code I’m writing.
//main.cpp
...
//cop.h
class cop
{
public:
....
class Person
{
private:
static char name;
static char age;
static char gender;
};
class Station
{
public:
Station();
~Station();
private:
Person personArray[20];
protected:
void visit();
};
//cop.cpp
char cop::Person::name;
char cop::Person::age;
char cop::Person::gender;
cop::Station::Station(){}
cop::Station::~Station(){}
Person cop::Station::personArray[20];
I get following ERROR;
‘Person’ does not name a type
First of all (as I’m pointing out later) the fields of
Personshould not bestatic. After that, remove the following lines:Properly designed your code should read like the following:
By the way: declaring all fields of the
Personclassstaticwill definitely make sure that all persons in your array have the same name, age and gender…