0
#include <iostream> 
#include <vector> 
using namespace std;  
class A  
{  
public:  
      A(int a);  
      static void print();//静态成员函数  
       static void change();//静态成员函数  
      static std::vector<int> aa;//静态数据成员的声明  
       static const int count;//常量静态数据成员(可以在构造函数中初始化)  
       const int bb;//常量数据成员  
};  

//静态成员的定义+初始化  
const int A::count=25;//静态常量成员定义+初始化  
A::A(int a):bb(a)//常量成员的初始化  
{  

} 

void A::change()
{
     A::aa.push_back(4);
} 
void A::print()  
{  
      change();
      cout<<"count="<<count<<endl;  
      cout<<"aa="<<A::aa[0]<<endl;  
}  

int main()  
{  
      A a(10);  
      A::print();//通过类访问静态成员函数  
      a.print();//通过对象访问静态成员函数 
      return 0; 
}  

I define a static vector in a class, and try to modify the elements in the vector,

but the compilation error "undefined reference to A::aa",I want to know how to modify static vector in class

0 Answers0