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

前端 未结 10 1677
悲哀的现实
悲哀的现实 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:46

    Imagine such a class definition:

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

    With the style of indentation you propose, one would need to change this into

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

    (which looks not so nice to many people, especially if the "implicit" section is long enough).


    I personally prefer half-indentation of such specifiers:

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

    But this is a matter of personal taste.

提交回复
热议问题