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> Wh开发者_开发百科ich 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.
精彩评论