One of the Question on C++ FAQ discusses correct way to declare local object within a function: http://www.parashift.com/c++-faq/fn-decl-vs-obj-instantiation.html
Given example from FAQ:
class Bar {
public:
Bar();
};
class Foo {
public:
Foo(Bar const& b);
void blah();
};
void yourCode()
{
Foo x(Bar()); // error
}
In VS2012, error is Foo x(Bar (__cdecl *)(void))': prototyped function not called (was a variable definition intended?)
Could someone explain me why this this declaration gives an error ?(C++ FAQ explanation is too vague).
Foo
and Bar
are both visible within body of yourCode()
, and Foo x(Bar());
is a way I would declare an object of type Foo
.