Can overriding be controlled ?

V

Vajira

Lets say there is a inheritance heirarchy like this. C3 inherit from C2
and C2 inherit from C1 ( C3 -> C2 -> C1 ). If C1 class has a public
virtual member function call 'Remove()', can I limit overriding this
member in C3 class ?
 
A

Alf P. Steinbach

* Vajira:
Lets say there is a inheritance heirarchy like this. C3 inherit from C2
and C2 inherit from C1 ( C3 -> C2 -> C1 ). If C1 class has a public
virtual member function call 'Remove()', can I limit overriding this
member in C3 class ?

I assume you mean whether you can do something in C2 such that C3
can be defined but cannot override the C1 member function.

In that case the answer is, AFAIK, no.

However, if you control the C1 implementation then you can add a dummy
argument of a private type. Then the function can only be overridden
by classes with access to that type. This does not, however, prevent
derived classes from offering a same-named function.
 
V

Vajira

Thank you, This is a nice idea.
Anyway, Isn't it nice to have a keyword like 'final' in Java for C++?
 
A

Attila Feher

Vajira said:
Thank you, This is a nice idea.
Anyway, Isn't it nice to have a keyword like 'final' in Java for C++?

I see this request popping up many times, but I have never seen anyone
telling a good enough reason for it. I do not recall needing it ever. Of
course I don't mean it is not needed, just that I don't know if it would be
worth the trouble.
 

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,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top