首页 > 解决方案 > 架构 x86_64 的未定义符号:静态类方法调用静态类成员

问题描述

这个问题让我感到很沮丧,我不知道如何解决它。

class A{
public:
    static int get_A() {
        return a;
    }
    static int get_B() {
        return b;
    }
    static int a;
    static int b;
};

int main() {
    int c = A::get_A(); 
    return 0;
}

我想在静态方法 get_A() 中使用静态,但我得到如下编译错误。(请原谅我在上面的程序中使用无意义的变量名)

Undefined symbols for architecture x86_64:
  "A::a", referenced from:
      A::get_A() in main.o

标签: c++

解决方案


推荐阅读