【发布时间】:2011-07-14 08:09:22
【问题描述】:
可能的重复:
constructor invocation mechanism
Why is it an error to use an empty set of brackets to call a constructor with no arguments?
为什么这个code 可以忽略A 的所有副本?
#include <iostream>
class A
{
public:
A() {}
A(const A&) { std::cout << "Copy" << std::endl; }
};
class B
{
public:
B(const A& a_) : a(a_) {}
private:
A a;
};
int main()
{
B b(A());
}
这段代码显然没有复制A,并且在 ideone 的 gcc 3.4 下不输出任何内容。
【问题讨论】:
标签: c++ most-vexing-parse