Indentation of "public" and "private" visibility modifiers [closed]
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() {}
}
精彩评论