Ambiguity between Parameterless constructor and '()' operator

Discussion in 'C++' started by debugEnthu, Jan 11, 2013.

  1. debugEnthu

    debugEnthu New Member

    Joined:
    Jul 5, 2012
    Messages:
    11
    Likes Received:
    3
    Trophy Points:
    0
    Hi,

    Following is the code snippet:
    Code:
     
        #include <stdio.h>  
        typedef double D;   
       class Action_Figure      
       {        D x;      
                public:       
                      Action_Figure( D a, D b ) { x = a * b; }        
                      Action_Figure( D a ) { x = a; }       
                      Action_Figure() { x = 5.0;
                      void operator()()         { printf("Action Level at %g\n", x); }      
       };  
    
         int main()      
       {      
             Action_Figure plane_man( 2.2, 8.6 );       
             Action_Figure train_man();       
             Action_Figure truck_man( 3.3 );       
             plane_man();       
             train_man();      
             truck_man();     
             return 0;       
       }
    
    Here , there would be ambiguity between
    operator and Action_Figure() constructor
    When I execute this i get the following error
    ( text+0x57): undefined reference to `train_man

    How do i resolve this when I need both the features..

    One workaround wat i thought was
    Code:
      class Action_Figure 
           {        D x;     
                    public:     
                      Action_Figure( D a, D b ) { x = a * b; }       
                      Action_Figure( D a ) { x = a; }       
                      Action_Figure() { x = 5.0;        
                      void operator()()
                     { printf("Action Level at %g\n", x); }  
             }train_man;
    However, It would be great I someone could suggest a better approach
     
    Last edited by a moderator: Jan 11, 2013
  2. Chong

    Chong New Member

    Joined:
    May 15, 2011
    Messages:
    29
    Likes Received:
    7
    Trophy Points:
    0
    Hi
    In your 1st code snippet,you should have
    Action_Figure train_man;
    instead of
    Actioin_Figure train_man();
    Best regards
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice