I have had a quite annoying problem which I have not been able to solve yet, so I would like to ask for Your expertise:
I am writing some evil science code which actually is a cellular automaton, whilst each cell may have update rules different enough to justify to attempt the problem using an OOP paradigm.
Since each cell must access its neighbouring cells, my idea was to save the whole field of cell as a multidimensional, static array in my node class. Unfortunately, the whole procedure apparently fails at the point when I try to access the functions of my class array.
Please consider the simplified code snippets below:
1 2 3 4 5 6 7 8 9 10 11 12 13
//BaseNode.h
class BaseNode
{
private:
static BaseNode **TheField;
void setChannel(short, double);
public:
void action(); //to be called externally
/...
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
//BaseNode.cpp
BaseNode BaseNode::**TheField=0;
void BaseNode::setChannel(short i, double value)
{
//Access member variable of this class
}
void BaseNode::action()
{
//Code to determine x,y
for(int i =0; i<9; i++)
{
TheField[x][y].setChannel(i,someValue); //Here is where I get the compile error: "undefined reference to 'BaseNode::TheField.
}
}
During compile time, I get an error message in which the compiler claims there is an undefined reference to 'BaseNode::TheField'. I have shot all my (probably limited) c++ knowledge on this, and I have become a bit frustrated.
I appreciate Your comment. Unfortunately, however, it does not work; my compiler [1] refuses the null macro. Furthermore, a small google search turned out that one is, firstly, let's say not encouraged to use null, and, secondly, that null is just a replacement for '0'.
Therefore, I would kindly ask to tell me what I did wrong or for other ideas.
MAE
[1] I am using the GCC package version 4.5.2 on a UBUNTU 11.04 machine.
The point of my post was not to try null instead of 0, but to put the ** before the BaseNode:: instead of after. **is part of the variable type, not part of the vriable name
Didn't that work either?