开发者

Should you write "public virtual" or "virtual public" in virtual inheritance?

开发者 https://www.devze.com 2023-02-20 15:17 出处:网络
Based on http://en.wikipedia.org/wiki/Virtual_inheritance class Animal { ... }; // Two classes virtually inheriting Animal:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消