1
我收到以下錯誤,我試過2種方法,但沒有解決它。錯誤:字符串常量或錯誤之前的預期標識符:'perf'不是一個類型
下面是代碼
class Stat_S{
public:
Stat_S(const char *name) :
{
........
}
~Stat_S();
};
struct temp {
Stat_S sp("ppin");
}
錯誤:字符串常量前的期望標識符
class Stat_S{
public:
Stat_S(const char *name) :
{
........
}
~Stat_S();
};
const char *temp="ppin";
struct temp {
Stat_S sp(temp);
}
錯誤: '溫度' 不是一個類型
class Stat_S{
public:
Stat_S(const char *name) :
{
........
}
~Stat_S();
};
struct temp {
Stat_S*sp = new Stat_S("ppin");
}
工作的優良任何錯誤
main()
{
static temp2 *temp;
temp2 = new temp[2];
}
如何解決第一或第二種情況?我想從struct temp調用Stat_S的構造函數。我不會使用第三種情況,因爲我已經有了使用點(。)作爲sp的大定義,我不想在使用實例後將其更改爲 - >。
你想要做什麼?在'struct temp'裏面,你不應該編寫可執行代碼,而是成員。代碼進入功能,而不是結構。如果你想有一個立即初始化的成員,那麼你需要'='或'{}'語法。你的語法只適用於局部變量(也就是在一個函數內) – leemes 2015-01-21 00:14:50
爲什麼是負值點。你能解釋一下嗎,下次我會更加謹慎。 – eswaat 2015-01-21 00:16:06
我沒有低調,但我想這是因爲你沒有解釋你想要做什麼。 – leemes 2015-01-21 00:16:50