no matching function to c'tor.

Discussion in 'C++' started by Gary Wessle, Nov 24, 2006.

  1. Gary Wessle

    Gary Wessle Guest

    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
     
    Gary Wessle, Nov 24, 2006
    #1
    1. Advertising

  2. Gary Wessle

    Kai-Uwe Bux Guest

    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
     
    Kai-Uwe Bux, Nov 24, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?T3Jlbg==?=

    C'tor of WebUserControl

    =?Utf-8?B?T3Jlbg==?=, Oct 16, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    497
    =?Utf-8?B?T3Jlbg==?=
    Oct 17, 2005
  2. =?Utf-8?B?T3Jlbg==?=

    C'tor of WebUserControl

    =?Utf-8?B?T3Jlbg==?=, Oct 17, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    489
    =?Utf-8?B?T3Jlbg==?=
    Oct 19, 2005
  3. Raffael Vogler
    Replies:
    8
    Views:
    1,256
    Chris Uppal
    Nov 30, 2003
  4. Mark McFarlane
    Replies:
    9
    Views:
    71,088
    javamazon
    Dec 20, 2011
  5. Jakob Bieling

    Q: c'tor and assignment operators

    Jakob Bieling, Jan 16, 2005, in forum: C++
    Replies:
    1
    Views:
    396
    Rolf Magnus
    Jan 16, 2005
Loading...

Share This Page