Why don't people indent C++ access specifiers/case statements?

前端 未结 10 1679
悲哀的现实
悲哀的现实 2020-12-16 11:13

I often see stuff like this:

class SomeClass {
public:
    void someMethod();
private:
    int someMember;
};

This seems totally unnatural

10条回答
  •  春和景丽
    2020-12-16 11:44

    Because public and private are labels which don't introduce a new scope, I prefer not to give them any special indentation, thus:

    class foo {
        public:
        void something();
        void something_else();
    
        private:
        int top_secret;
    };
    

    This way, the consistent indentation rule is "indentation equals scope".

提交回复
热议问题