2
可能重複:
Most vexing parse: why doesn't A a(()); work?
Difference between creating object with() or without初始化對象的與默認的構造
有這樣的代碼:
class MojaKlasa{
public:
MojaKlasa(){}
MojaKlasa(int i){}
void fun(){}
};
int main()
{
MojaKlasa a;
a.fun();
MojaKlasa b(1);
b.fun();
MojaKlasa c(); // initialize with default constructor
//c.fun(); error: request for member ‘fun’ in ‘c’, which is of non-class type ‘MojaKlasa()’
return 0;
}
- 爲什麼對象c有錯誤?
- 使其工作的方式是什麼?
- 真的意味着什麼MojaKlasa c() - 它是函數聲明嗎?
Lookup **在C++中最令人生厭的解析**。 –
這不是最令人頭疼的解析,最令人頭痛的解析是,當您嘗試在初始化直接聲明中使用臨時初始化值作爲初始值時。 –