Monday 15 January 2018

c++ - how to use the operator of parent class?

itemprop="text">











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.


itemprop="text">
class="normal">Answer



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



#include



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;
}


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...