2011-02-10 27 views
12

我通常縮進這樣的public:private:訪問說明:縮進「公」和「私」可見性修飾符的

class Foo() 
{ 
    private: 

    void Bar1() {} 

    public: 

    void Bar2() {} 
} 

Xcode中似乎並不不過這樣子,所以我感覺我我做錯了一些事情。縮進private:public:的常見做法是什麼?

+0

are they tags ?? – BlackBear 2011-02-10 17:22:05

+0

@BlackBear我不知道還有什麼可以稱呼他們。 – Maxpm 2011-02-10 17:23:13

+0

我認爲(我不是C++的人)那些屬性 – BlackBear 2011-02-10 17:26:26

回答

7

宗教問題:-)你會得到很多不同的答案,我想。

我說: 只要你一致,你會喜歡哪一個。

5

就像標籤:

class Foo() 
{ 
private: 

    void Bar1() {} 

public: 

    void Bar2() {} 
} 
7

Visual Studio中做到這一點:

class Foo() 
{ 
private: 

    void Bar1() {} 

public: 

    void Bar2() {} 
} 

可是,我討厭它。許多人使用它。如果只有C++支持的字段/方法特定的可見性修飾符像大多數語言那樣。

我個人很喜歡用這樣的:

class Foo() 
{ 
    private: 

     void Bar1() {} 

    public: 

     void Bar2() {} 
} 

VS通常保持它恢復到它的縮進方案,所以我往往只是提交。

3

如果你要遵循一個風格指南,我建議Google C++ Style Guide

節在公共,保護和私有秩序,各縮進1個空格。