Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   no matching function to c'tor. (http://www.velocityreviews.com/forums/t458671-no-matching-function-to-ctor.html)

Gary Wessle 11-24-2006 05:18 AM

no matching function to c'tor.
 

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

Kai-Uwe Bux 11-24-2006 05:53 AM

Re: no matching function to c'tor.
 
Gary Wessle wrote:

>
> 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.

> A a(tt);


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


All times are GMT. The time now is 11:13 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.