home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 32,720 of 33,346   
   Thomas Richter to All   
   Re: Conversion, operator overloading   
   11 Dec 12 22:19:39   
   
   From: thor@math.tu-berlin.de   
      
   On 11.12.2012 21:30, TS wrote:   
      
   > recently I got a problem related to conversion and operator overloading.   
   > With the code below   
   >   
   > class A {};   
   > A operator +(const A&  lhs, const A&  rhs) { ... };   
   >   
   > class B {   
   > public:   
   >      operator A() { ... }   
   >      operator int() { ... }   
   > };   
      
   > I got the error from gcc:   
   > error: ambiguous overload for ‘operator+’ in ‘ba + bb’   
   > note: candidates are: operator+(int, int)   
   > note:                 A operator+(const A&, const A&)   
   >   
   > I'm wondering how I can get rid of the error.   
      
   Provide an operator + that operates on B by calling the conversion   
   explicitly:   
      
   A operator +(const B& lhs, const B& rhs) { ... };   
      
   HTHH,   
      
   	Thomas   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca