我在我的書下面的語句:
編譯器何時不創建默認構造函數?
如果我們給予任何構造了一類無論是
1.我們自己explcit默認構造函數(即無參數或具有默認 參數值)
或
2.我們自己的構造函數的參數
那麼編譯器不會產生隱含的默認構造要麼。
但我對第2點有懷疑,我懷疑我的書籍ID不正確或過時,因爲我的下面的代碼確實有一個帶參數的構造函數,但編譯器也在生成內部構造函數。
#include <iostream>
class imminent{
public:
imminent(int x, int y){
std::cout << "I am explicit constructor" << std::endl;
}
};
int main(){
imminent gilfray(); /* compiler creates internal default constructor
that why this line is compiled without errors*/
imminent jimmy(1, 2);
}
而且,我怎樣才能把我的C++代碼在這裏,因爲這一次我是被迫的代碼片段用JS真正的出路,是不是有任何的C++代碼共享選項?
看看最煩人的解析:http://en.wikipedia.org/wiki/Most_vexing_parse。 '即將gilfray();'是一個函數返回'迫在眉睫' – 2014-11-24 18:19:41