我有以下兩類:是否允許實例化一個類沒有指定的變量名在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