DBQ
October 8th, 2010, 09:05 PM
Hi everybody,
I got a question. I have the following code.
#include <list>
using namespace std;
class A
{
public:
static A* f(int a)
{
A* new_A = new A(a);
list_of_A.push_back(new_A);
return new_A;
}
protected:
static list<A*> list_of_A;
A(int a)
{
a = 100;
}
};
int main()
{
A* myA = A::f(100);
return 0;
}
when I compile it, I get error: undefined reference to `A::list_of_A'. The thing is, if I remove line
A* myA = A::f(100); from main, then everything is fine. Why is this happening? Any ideas how to fix it? Help is appreaciated.
I got a question. I have the following code.
#include <list>
using namespace std;
class A
{
public:
static A* f(int a)
{
A* new_A = new A(a);
list_of_A.push_back(new_A);
return new_A;
}
protected:
static list<A*> list_of_A;
A(int a)
{
a = 100;
}
};
int main()
{
A* myA = A::f(100);
return 0;
}
when I compile it, I get error: undefined reference to `A::list_of_A'. The thing is, if I remove line
A* myA = A::f(100); from main, then everything is fine. Why is this happening? Any ideas how to fix it? Help is appreaciated.