-2
Class base{
public :
static vector<int> _elems;

... How can I use that static one.Must I define it out of the class body again? Or I meet a trouble about a error"Undefine reference to 'base::_elems'"

2 Answers2

0

You've only declared the static member, never defined it. In your cpp file you need to do this:

vector<int> base::_elems;
mbgda
  • 787
  • 5
  • 8
0

You can use it like any other variable. You only need to remember that the static variable is the same for all instances.

Edit: I forgot the defenition. You must define the variable, this can be done from any cpp file, but i recommend to define the variable in the file base.cpp.

MvHorssen
  • 111
  • 2
  • 12