can operators be inherited?

P

puzzlecracker

I don't recall whether operators, which are members of the class, are
intherited in subclasses?

thanks
 
V

Victor Bazarov

puzzlecracker said:
I don't recall whether operators, which are members of the class, are
intherited in subclasses?

If you meant to ask whether they were inherited, then, yes, they are,
just like any other function.

If you meant to ask if we thought you didn't recall, we don't know.

V
 
V

Victor Bazarov

Victor said:
If you meant to ask whether they were inherited, then, yes, they are,
just like any other function.

Correction: except for 'address of', I believe. And keep in mind that
each class has its own operator= that hides any inherited operator=.

V
 
P

puzzlecracker

Correction: except for 'address of', I believe. And keep in mind that
each class has its own operator= that hides any inherited operator=.

V

Thanks V,

What if I make operators virtual in the base class, would they still
be hidden - or according to the standard, operators cannot be
virtual?

Thanks agai,
 
V

Victor Bazarov

puzzlecracker said:
[..]
What if I make operators virtual in the base class, would they still
be hidden - or according to the standard, operators cannot be
virtual?

Hiding and overriding are two different concepts, but hiding can be
overcome by "using" declarations (see FAQ).

V
 
J

James Kanze

What if I make operators virtual in the base class, would they still
be hidden - or according to the standard, operators cannot be
virtual?

As far as the definition goes, a user defined operator is just a
function with a funny name, and it obeys all of the rules of a
function.

A more general comment, however: C++ operators are value
oriented, and values and polymorphism don't really mix very
well. So the presence of a virtual operator is *usually* a
symptom of a design error (although there are one or two
specific idioms, like letter/envelope where it makes sense).
Just because you can do something doesn't mean that you should.
 

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
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top