2
以下代碼不調用複製構造函數。這是複製構造函數elision嗎?
struct X
{
int x;
X(int num)
{
x = num;
std::cout << "ctor" << std::endl;
}
X(const X& other)
{
std::cout << "copy ctor" << std::endl;
}
};
int main(int argc, _TCHAR* argv[])
{
X* x = new X(3);
X* y(x);
}
輸出:
ctor
難道是複製構造函數省音?
我看不到一份甚至可能被忽略的副本。你確定你的例子是正確的嗎? –
@CharlesBailey well'X(const X&other)'**可以在正確的上下文中被忽略(事實並非如此)。 –
請不要用Java書學習C++,它對任何人都沒有好處。 –