class A
{
public:
static bool S(int);
static string str;
static int integer;
};
bool A::S(int)
{
str+="A";
}
當我構建程序時,會發生錯誤:「str」未聲明的標識符。Static Function
class A
{
public:
static bool S(int);
static string str;
static int integer;
};
bool A::S(int)
{
str+="A";
}
當我構建程序時,會發生錯誤:「str」未聲明的標識符。Static Function
也許你有一個以上的錯誤,而你圍繞你的注意力放在一個是最重要的:
string
沒有指定類型str
未申報。str
未定義,因爲用於定義它的類型不存在。
的解決辦法是在文件的開頭添加
#include <string>
using namespace std;
(不,我的電子書籍線using
無論如何,但那是另一回事)。
您應該始終把注意力放在編譯器問題的第一個錯誤上。但是一些流行的IDE對於重新排序它們值得注意。
即使您僅使用int
s,也會忽略該類型未定義的類型,但仍會出現此錯誤。
您正在看到的錯誤是因爲您缺少您的靜態變量的定義。你只有才宣稱爲。
string A::str = "initial value";
參見:What is the difference between a definition and a declaration?
請添加相關的語言標記你的問題。 –
未定義的標識符 – user1991893