C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Enforcing virtual/non virtual derivation

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Nicola.Musatti@ObjectWay.
Guest





PostPosted: Mon Jan 10, 2005 8:08 pm    Post subject: Enforcing virtual/non virtual derivation Reply with quote



Hallo,
I have a complex hyerarchy of abstract classes where some of the bases
must be inherited from virtually while others should not. I would be
grateful for help in ensuring that these classes are always used
correctly.

Thank you,
Nicola Musatti


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Nicola.Musatti@ObjectWay.
Guest





PostPosted: Wed Jan 12, 2005 9:11 pm    Post subject: Re: Enforcing virtual/non virtual derivation Reply with quote



I'll answer part of my own question. In order to enforce virtual
derivation in the presence of multiple inheritance from the same base
class you can simply add a dummy pure virtual function in the base
class. Concrete derived classes must then override this function, which
is not possible if the class that's multiply inherited is not inherited
from virtually.
Not a complete solution, though.

Cheers,
Nicola Musatti


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Allan W
Guest





PostPosted: Thu Jan 13, 2005 12:13 pm    Post subject: Re: Enforcing virtual/non virtual derivation Reply with quote



[email]Nicola.Musatti (AT) ObjectWay (DOT) it[/email] wrote:
Quote:
I have a complex hyerarchy of abstract classes where some of the
bases
must be inherited from virtually while others should not. I would be
grateful for help in ensuring that these classes are always used
correctly.

I would suggest naming conventions. Classes that must be inherited
virtually should have names that start with iv_ (for "Inherit
Virtually"). Classes that must not should have names that start with
niv_ ("Never Inherit Virtually"). The vast majority would have no
prefix.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Nicola.Musatti@ObjectWay.
Guest





PostPosted: Wed Jan 19, 2005 2:05 am    Post subject: Re: Enforcing virtual/non virtual derivation Reply with quote

As is often the case, a minute after hitting send I realized I wrote
something stupid. There's no problem overriding a virtual function from
a virtual base class, even if that base class appears more than once in
the hyerarchy. I'll have to find something else.
Cheers,
Nicola Musatti


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.