| View previous topic :: View next topic |
| Author |
Message |
Nicola.Musatti@ObjectWay. Guest
|
Posted: Mon Jan 10, 2005 8:08 pm Post subject: Enforcing virtual/non virtual derivation |
|
|
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
|
Posted: Wed Jan 12, 2005 9:11 pm Post subject: Re: Enforcing virtual/non virtual derivation |
|
|
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
|
Posted: Thu Jan 13, 2005 12:13 pm Post subject: Re: Enforcing virtual/non virtual derivation |
|
|
[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
|
Posted: Wed Jan 19, 2005 2:05 am Post subject: Re: Enforcing virtual/non virtual derivation |
|
|
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 |
|
 |
|