【发布时间】:2019-12-10 23:07:05
【问题描述】:
我正在使用 extern 从另一个类中获取变量,它适用于 int、float 等...
但这不起作用,我不知道该怎么做:
Class1.cpp
struct MyStruct {
int x;
}
MyStruct theVar;
Class2.cpp
extern MyStruct theVar;
void test() {
int t = theVar.x;
}
它不起作用,因为 Class2 不知道 MyStruct 是什么。
我该如何解决这个问题?
我尝试在 Class2.cpp 中声明相同的结构,并编译,但值错误。
【问题讨论】:
标签: c++