overloading

T

Tony Johansson

Hello!!

Does anybody know what this mean
If the base class defines a private overloaded assignment operator, the
derived class must define this operator also.

I know this about inheritance and assignment operator so the above row
doesn't fit in my understanding.
If you have inheritance you must always define the assignment operator for
each class and call the base class for each subclass.

//Tony
 
R

Rolf Magnus

Tony said:
Hello!!

Does anybody know what this mean
If the base class defines a private overloaded assignment operator, the
derived class must define this operator also.

Out of context, it doesn't mean anything.
I can just guess that it is supposed to say that - if you make the base
class's assignment operator private - the compiler cannot generate one for
the derived class, so you have to define it yourself it you want to use it.
I know this about inheritance and assignment operator so the above row
doesn't fit in my understanding.
If you have inheritance you must always define the assignment operator for
each class

You don't _have_ to. If the compiler-generated one fits, you can (and
should) use that instead.
and call the base class for each subclass.

That's the most sensible thing to do in most cases, but still isn't really
required.
 
V

Victor Bazarov

Tony said:
Does anybody know what this mean
If the base class defines a private overloaded assignment operator, the
derived class must define this operator also.

I know this about inheritance and assignment operator so the above row
doesn't fit in my understanding.
If you have inheritance you must always define the assignment operator for
each class and call the base class for each subclass.

You won't be able to call the base class' assignment operator if it's
declared private.

In general, you don't need to define an assignment op in your class if
it's trivial. However, the default assignment operator cannot be
implemented by the compiler if any of the base classes declare their
assignment op as private. That's why you will be forced to define one
in the derived class and make sure you work around the private-ness of
the base's assignment op.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,203
Messages
2,571,059
Members
47,668
Latest member
SamiraShac

Latest Threads

Top