开发者

Indentation of "public" and "private" visibility modifiers [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debat开发者_高级运维e, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 12 years ago.

I usually indent the public: and private: access specifiers like this:

class Foo()
{
    private:

    void Bar1() {}

    public:

    void Bar2() {}
}

Xcode doesn't seem to like this, however, so I feel like I'm doing something incorrectly. What is considered common practice for indenting private: and public:?


"Religious" question :-) You will get many different answers I think.

I say:
Which ever you like as long as you are consistent.


Visual Studio does this:

class Foo()
{
private:

    void Bar1() {}

public:

    void Bar2() {}
}

But I hate it. Many people use it though. If only C++ supported field/method specific visibility modifiers like most languages out there.

I personally like to use this:

class Foo()
{
    private:

        void Bar1() {}

    public:

        void Bar2() {}
}

VS usually keeps reverting it to its indentation scheme, so I often just submit.


If you want to follow a Style Guide, I suggest the Google C++ Style Guide:

Sections in public, protected and private order, each indented one space.


Just like labels:

class Foo()
{
private:

    void Bar1() {}

public:

    void Bar2() {}
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜