4

Possible Duplicate:
How to use base class's constructors and assignment operator in C++?

class A
{
protected:
    void f();
}

class B : public A
{
protected:
    void f()
    {
         A::f();
    }
}

We can use the function of parent class in this way, but I don't know how to use the operator of parent class.

Community
  • 1
  • 1
Gimun Eom
  • 411
  • 5
  • 17
  • (I guessed this was C++; please correct if I guessed wrong by editing your question and putting the appropriate language tag.) – Mat Apr 09 '12 at 09:43
  • http://stackoverflow.com/questions/1226634/how-to-use-base-classs-constructors-and-assignment-operator-in-c has some examples of calling operators from a parent class in C++ – Mat Apr 09 '12 at 09:44

1 Answers1

6

Operators of user defined types are just member functions with funky names. So, it goes pretty similarly to your example:

#include <iostream>

class A
{
protected:
    A& operator++() { std::cout << "++A\n"; return *this; }
};

class B : public A
{
public:
    B& operator++()
    {
        A::operator++();
        return *this;
    }
};


int main()
{
    B b;
    ++b;
}
jrok
  • 54,456
  • 9
  • 109
  • 141