带有完全静态类的“未定义引用”

时间:2018-06-04 21:01:59

标签: c++ class compiler-errors static linker-errors

以下代码

#include <iostream>

class X          // fully static class
{
  private:
     static int x;
  public:
     static int get()
     {
         return x;
     }
     static void set(int i)
     {
         x = i;
     }
};


int main()
{
    X::set(3);
    std::cout << X::get() << std::endl;

    return 0;
}

导致在编译时看起来像链接问题

undefined reference to `X::x'

是什么导致了这个问题?

0 个答案:

没有答案
相关问题