0
所以我test.h
其中包含:無法從另一頭文件調用函數時不在主
#ifndef TEST_H_
#define TEST_H_
class test {
public:
int value;
};
#endif /* TEST_H_ */
和我main.cpp
:
#include "test.h"
class Magic {
test x;
x.value = 2; // Syntax error
};
int main() {
test y;
y.value = 2; // Works fine
return 0;
}
這究竟是爲什麼?
你不能把任意代碼像這樣一類的聲明。這就是語言的定義。 – Borgleader
你從中學到了什麼書/教程,代碼是這樣寫的? –
所以要使用'test'我必須在主要功能? – SomeoneWithAQuestion