我有以下两类:是否允许实例化一个类没有指定的变量名在C++
class Foo
{
public:
Foo() { std::cout << "in Foo constructor" << std::endl; }
};
class Bar
{
public:
Bar() {};
Bar(Foo foo);
private:
Foo m_foo;
};
Bar::Bar(Foo foo) :
m_foo(foo)
{
std::cout << "in Bar constructor with argument Foo" << std::endl;
}
int main() {
Bar bar(Foo()); // is something wrong here ?
return 0;
}
我编译和excuted吧,没什么显示在屏幕上,什么也Bar bar(Foo())
办? 我看到Do the parentheses after the type name make a difference with new?和Foo f = Foo(); // no matching function for call to 'Foo::Foo(Foo)'的相似性,但我仍然无法弄清楚。
最令人头疼的解析。 – Pubby 2013-04-05 04:10:52
的确最令人烦恼的解析。看看http://en.wikipedia.org/wiki/Most_vexing_parse! – Nbr44 2013-04-05 04:13:19