T
thomas
#include <iostream>
using namespace std;
class bar{
public:
bar(){}
};
class foo{
public:
foo(bar& b){}
foo(int x=0){}
void blah(){
cout<<"blah"<<endl;
}
};
void yourcode(){
foo x(bar()); //error <1>
foo xx(int);
// foo x = foo(bar()); //works
// foo x = bar(); //works
x.blah();
}
int main(){
yourcode();
}
---------------code------------------
FAQ 10.19(http://www.parashift.com/c++-faq-lite/ctors.html) says that
<1> is wrong because:
When the compiler sees Foo x(Bar()), it thinks that the Bar() part is
declaring a non-member function that returns a Bar object, so it
thinks you are declaring the existence of a function called x that
returns a Foo and that takes as a single parameter of type "non-member
function that takes nothing and returns a Bar."
My question is how can "Bar()" declare a function without a name?
For example:
void ();
This declaration is illegal as the compiler complains.
using namespace std;
class bar{
public:
bar(){}
};
class foo{
public:
foo(bar& b){}
foo(int x=0){}
void blah(){
cout<<"blah"<<endl;
}
};
void yourcode(){
foo x(bar()); //error <1>
foo xx(int);
// foo x = foo(bar()); //works
// foo x = bar(); //works
x.blah();
}
int main(){
yourcode();
}
---------------code------------------
FAQ 10.19(http://www.parashift.com/c++-faq-lite/ctors.html) says that
<1> is wrong because:
When the compiler sees Foo x(Bar()), it thinks that the Bar() part is
declaring a non-member function that returns a Bar object, so it
thinks you are declaring the existence of a function called x that
returns a Foo and that takes as a single parameter of type "non-member
function that takes nothing and returns a Bar."
My question is how can "Bar()" declare a function without a name?
For example:
void ();
This declaration is illegal as the compiler complains.