By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,370 Members | 1,534 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,370 IT Pros & Developers. It's quick & easy.

Can overriding be controlled ?

P: n/a
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 ?

Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
* 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.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #2

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

Jul 22 '05 #3

P: n/a
Vajira wrote:
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.

--
Attila aka WW
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.