c++ - 架构 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
解决方案
推荐阅读
- android - 如何解决警告 - 对于 Android 11 中不可用的 Google 地图版本 1
- javascript - Javascript - 开始文本输入时只读
- php - jQuery将dict附加到html,如何从1插入一个自动递增的id
- android - 如何向 Azure Bot 发送短信?
- python - 网页抓取问题 - 在页面源中看不到数据
- python-3.x - 如何在熊猫数据框中查找缺失的索引值?
- amazon-web-services - 如果在 terraform 中未指定提供程序版本约束并且涉及重大更改,会发生什么情况
- vue.js - 使用自定义主机名时,热重载不适用于 Vue CLI 项目
- sql - SQL Server 阻止更新列(插入时数据库设置的 datetime2 列值)
- c# - 读取服务器的证书存储