How to call an operator as function in C++

Viewed 22045

I want to call a specific operator of specific base class of some class. For simple functions it's easy: I just write SpecificBaseClass::function( args );. How should I implement the same for operators without casting trickery?

Isolated problem:

 class A
 {
 public:
     A operator+( const A &other ) const {...}
 };

 class B : public A
 {
 public:
     B operator+( const B & other ) const {...}

 };

 ...
  B a, b;
  B c = A::operator+( a, b ); //how this should be implemented? I get an error
 ...

I'm getting the following error from GCC4.5.1:

error: no matching function for call to ‘A::operator+(B&, B&)’
note: candidate is: A A::operator+(const A&) const

Thanks!


EDIT
I've improved the example to better illustrate the problem.

6 Answers
Related