"private member" : undeclared identifier

Oct 24, 2009 at 5:36pm
Hi! I have made a class in whose private members i have included two arrays which I initialize in the class definition rather than the constructor. However, when i try to call any array of the two from a member function, the compiler shows this message:

error C2065: 'adjacency_list' : undeclared identifier
error C2065: 'directions' : undeclared identifier

any ideas???

also, since i am asking this, directions[] is of type enum color {WHITE, = 0, GRAY, BLACK}. is that possible or am i writing nonsense?
Oct 24, 2009 at 5:44pm
i am using microsoft visual studio 2008
Oct 24, 2009 at 7:07pm
i have included two arrays which I initialize in the class definition rather than the constructor
What does that mean?
Can you post some of the code?
Oct 25, 2009 at 1:27am
this is the code:

#include <queue>
using namespace std;

enum color {WHITE = 0, GRAY, BLACK};
enum direction {UP = 1, RIGHT, DOWN, LEFT, N = 10};

class Vertex {
public:
color c; // color
short d; // distance
short n; // number
Vertex *p; // predecessor
};

class Map {
public:
Map();
~Map();

void setAL(int, int, bool);
bool getAL(int, int);
bool *getAL();
direction getDirection(int, int);
Vertex vertex[17];

void BFS(bool[], Vertex);

private:
void initializeJunctions();
bool adjacency_list[17][17] = { { false , true , false , false , false , false , true , false , false , false , false , false , false , false , false , false , false },
{ true , false , true , false , false , false , false , false , false , false , false , false , false , false , false , false , false },
{ false , true , false , true , false , false , false , false , false , false , false , false , false , false , false , false , false },
{ false , false , true , false , true , false , false , false , false , false , false , false , false , false , false , false , false },
{ false , false , false , true , false , true , false , true , false , false , false , false , false , false , false , false , false },
{ false , false , false , false , true , false , true , false , false , false , false , false , true , false , false , false , false },
{ true , false , false , false , false , true , false , false , false , false , false , false , false , false , false , false , false },
{ false , false , false , false , true , false , false , false , true , false , false , false , false , true , false , false , false },
{ false , false , false , false , false , false , false , true , false , true , false , false , false , false , false , false , false },
{ false , false , false , false , false , false , false , false , true , false , true , false , false , false , true , false , false },
{ false , false , false , false , false , false , false , false , false , true , false , true , false , false , false , true , false },
{ false , false , false , false , false , false , false , false , false , false , true , false , false , false , false , false , true },
{ false , false , false , false , false , true , false , false , false , false , false , false , false , false , false , false , false },
{ false , false , false , false , false , false , false , true , false , false , false , false , false , false , false , false , false },
{ false , false , false , false , false , false , false , false , false , true , false , false , false , false , false , false , false },
{ false , false , false , false , false , false , false , false , false , false , true , false , false , false , false , false , false },
{ false , false , false , false , false , false , false , false , false , false , false , true , false , false , false , false , false } };

direction directions[17][17] = { { N , RIGHT , N , N , N , N , DOWN , N , N , N , N , N , N , N , N , N , N },
{ LEFT , N , RIGHT , N , N , N , N , N , N , N , N , N , N , N , N , N , N },
{ N , LEFT , N , DOWN , N , N , N , N , N , N , N , N , N , N , N , N , N },
{ N , N , UP , N , LEFT , N , N , N , N , N , N , N , N , N , N , N , N },
{ N , N , N , RIGHT , N , UP , N , LEFT , N , N , N , N , N , N , N , N , N },
{ N , N , N , N , DOWN , N , UP , N , N , N , N , N , RIGHT , N , N , N , N },
{ UP , N , N , N , N , DOWN , N , N , N , N , N , N , N , N , N , N , N },
{ N , N , N , N , RIGHT , N , N , N , LEFT , N , N , N , N , DOWN , N , N , N },
{ N , N , N , N , N , N , N , RIGHT , N , UP , N , N , N , N , N , N , N },
{ N , N , N , N , N , N , N , N , DOWN , N , UP , N , N , N , LEFT , N , N },
{ N , N , N , N , N , N , N , N , N , DOWN , N , UP , N , N , N , LEFT , N },
{ N , N , N , N , N , N , N , N , N , N , DOWN , N , N , N , N , N , LEFT },
{ N , N , N , N , N , LEFT , N , N , N , N , N , N , N , N , N , N , N },
{ N , N , N , N , N , N , N , UP , N , N , N , N , N , N , N , N , N },
{ N , N , N , N , N , N , N , N , N , RIGHT , N , N , N , N , N , N , N },
{ N , N , N , N , N , N , N , N , N , N , RIGHT , N , N , N , N , N , N },
{ N , N , N , N , N , N , N , N , N , N , N , RIGHT , N , N , N , N , N } };
};

the problem arises when i call the get and set functions:

void Map::setAL(int a, int b, bool w)
{
adjacency_list[a][b] = w;
}

bool Map::getAL(int a, int b)
{
bool c = adjacency_list[a][b];
return c;
}

bool *Map::getAL()
{
return adjacency_list;
}

direction Map::getDirection(int a, int b)
{
direction dir = directions[a][b];
return dir;
}

and the compiler shows up the errors:
error C2065: 'adjacency_list' : undeclared identifier
error C2065: 'directions' : undeclared identifier
Oct 25, 2009 at 6:33am
I'm sure that if you gave that code to the compiler - It will give a lot more errors than the two you have told us.

To start:

1. You cannot initialize arrays inside a class declaration .





Oct 25, 2009 at 2:47pm
is that true for all types of variables or just arrays? how should i initialize them? should i initialize them in the constructor? any other obvious errors in my code?
Oct 25, 2009 at 2:51pm
is that true for all types of variables or just arrays?
Currently, only static const integral types can be initialized in the class body
how should i initialize them? should i initialize them in the constructor?
Yes
Oct 25, 2009 at 3:02pm
you can't initialize members in your class definition.
Topic archived. No new replies allowed.