titanandrews
Programmer
Hi All,
Can someone kindly tell me what is the proper way to initialize a static member list in C++? I have the following code:
In the ctor I call the static method init_list, but that gives me a linker error. I am really not sure why. Can someone provide a clue?
Many thanks for your help!
-B
Can someone kindly tell me what is the proper way to initialize a static member list in C++? I have the following code:
Code:
#include <iostream>
#include <vector>
using namespace std;
class Foo
{
public:
Foo();
virtual ~Foo();
static vector<int> ilist;
static void init_list();
};
inline Foo::Foo()
{
Foo::init_list(); // This line gives a linker error.
}
inline Foo::~Foo()
{
}
inline void Foo::init_list()
{
Foo::ilist.push_back(100);
}
int main(int argc, char* argv)
{
Foo foo;
}
In the ctor I call the static method init_list, but that gives me a linker error. I am really not sure why. Can someone provide a clue?
Many thanks for your help!
-B