This completely sums up the problem I am having right now:
class A{
public:
int Avar;
A(int Avar = 0){this->Avar = Avar;}
};
class B{
private:
static A *AArray;
public:
static void setAArray();
};
int main(){
return 0;
}
void B::setAArray(){
A *data;
data = new A[10];
AArray = data; // <- delete this line and the program complies
}
This piece of code says I have an undefined reference to 'B::AArray' and won't compile. How do I resolve this if I want a static pointer to an array of class A objects in class B?
Note: my class does not use multiple files currently and everything is under one .cc file
Edit: the question that is marked as duplicate as does not deal with a pointer or with an array of objects from another class. Tried solution from said post with no results.
A B::AArray;
orA B::AArray = new A[10];
gives me multiple errors including "conflicting declaration" and "cannot be initialized by a non-constant expression". I can't seem to figure out a way to define B::AArray anywhere – Potato Salad Jan 23 '17 at 11:46