no matching function to c'tor.

G

Gary Wessle

Hi
the errors below the code here is my problem. I don't understand
why. can you please help.

thanks

class Test
{
public:
Test(){}
};

class A
{
Test t;
public:
A(Test x):t(x){}
};

int main(){
Test tt();
A a(tt);

}

****************************************************************
cd /home/fred/myProg/toy/
make -k
g++ -gdwarf-2 -c -o main.o main.cpp
main.cpp: In function ‘int main()’:
main.cpp:16: error: no matching function for call to ‘A::A(Test (&)())’
main.cpp:11: note: candidates are: A::A(Test)
main.cpp:8: note: A::A(const A&)
make: *** [main.o] Error 1
make: Target `proj' not remade because of errors.

Compilation exited abnormally with code 2 at Fri Nov 24 16:16:10
 
K

Kai-Uwe Bux

Gary said:
Hi
the errors below the code here is my problem. I don't understand
why. can you please help.

thanks

class Test
{
public:
Test(){}
};

class A
{
Test t;
public:
A(Test x):t(x){}
};

int main(){
Test tt();

The line above does not declare a variable of type Test but a Test-valued
function without arguments. (This really should be a FAQ, but I didn't find
it.) The rule of thumb is: if it can be parsed as a function declaration,
then it is.

And here the compiler realizes that there is no way to construct an A object
from a function void->Test.
[snip]


Best

Kai-Uwe Bux
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top