-1

if I have a static member variable of a class A declared in the file Af.h and I want to use this variable inside a method "met" of this same class inside the file Af.cpp, how do I proceed? here is my files

Af.h

class A
{
  public:
    static std::vector <int> vec;
    void met();
//....
};

Af.cpp

//...
void A::met()
{
// I will use here some int variable i
vec.push_back(i);
//...
}

Unfortunately,this code provides the following compiling error:

undefined reference to A::vec
Saddam
  • 25
  • 8

1 Answers1

0

You need to define it in Af.cpp:

std::vector<int> A::vec;
songyuanyao
  • 169,198
  • 16
  • 310
  • 405