Based on http://en.wikipedia.org/wiki/Virtual_inheritance
class Animal
{
...
};
// Two classes virtually inheriting Animal:
class Mammal : public virtual Animal
{
...
};
I also saw books use the following syntax,
class Mammal : virtual public Animal
{
...
};
Question> Which is one the C++ standard?
Thank you
From ISO/IEC 14882:2003(E) - 10.1
A list of base classes can be specified in a class definition using the notation:
base-clause:
: base-specifier-list
base-specifier-list:
base-specifier
base-specifier-list , base-specifier
base-specifier:
::opt nested-name-specifieropt class-name
virtual access-specifier opt ::opt nested-name-specifieropt class-name
access-specifier virtual opt ::opt nested-name-specifieropt class-name
access-specifier:
private
protected
public
Notice that either is recommended.
Both are standard. Use whichever the local coding conventions require.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With