c++类中static struct member 静态结构体成员变量 undefined reference错误解决方案

问题解决方案参考
https://stackoverflow.com/questions/15021879/static-struct-member-gets-undefined-reference-dont-know-why

// 在类的声明h文件中
class Foo
{
 public:
   static int app_counter;

   typedef struct
   {
       double eed;
       int bits;  
   }APPLayer;

   static APPLayer applayer_metric;
public:
   Foo(){};
   ~Foo();
};
// 在类的定义cpp文件中
#include "Foo.h"
int Foo::app_counter=0;
//How do I set all internal members to zero?
Foo::APPLayer applayer_metric;
Foo::~Foo()
{
  std::cout << app_counter << std::endl; 
  //Which is the way to access to the values of my members?
  std::cout << applayer_metric.bits << std::endl;
}

会得到undefined reference to `Foo::applayer_metric’错误

你可能感兴趣的:(c++)