Ambiguity between Parameterless constructor and '()' operator

debugEnthu's Avatar
Go4Expert Member
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 shabbir; 11Jan2013 at 17:38.. Reason: Code blocks
Chong's Avatar, Join Date: May 2011
Go4Expert Member
Hi
In your 1st code snippet,you should have
Action_Figure train_man;
instead of
Actioin_Figure train_man();
Best regards