|
http://www.jindent.com |
Previous: Directives/Macros
|
Next: Method/Constructor
|
try-catch)try-catch statementstry-catch statements can be formatted different than methods.| Brace style for class/struct/union type declarations |

| Left brace { new line |
|
class MyClass : public MyOtherClass { ... |
|
class MyClass : public MyOtherClass { ... |
| Right brace } new line |
| Indent left brace { |
|
class·MyClass·:·public·MyOtherClass ····{ ····... |
|
class·MyClass·:·public·MyOtherClass { ... |
|
class·MyClass·:·public·MyOtherClass·{ ... |
|
class·MyClass·:·public·MyOtherClass{ ... |
| Indent right brace } |
|
class·MyClass·:·public·MyOtherClass ····{ ····... ····} |
|
class·MyClass·:·public·MyOtherClass { ····... } |
| Indent after right brace } |
| Cuddle braces of empty blocks {} |
|
class MyClass : public MyOtherClass {} |
|
class MyClass : public MyOtherClass { } |
| Indent cuddled braces {} |
|
class·MyClass·:·public·MyOtherClass{} |
|
class·MyClass·:·public·MyOtherClass·{} |
| Prohibit blank lines after left brace { |
|
class MyClass : public MyOtherClass { ¶ // comment with a preceding blank line int field; ¶ // another comment ... } |
|
class MyClass { // comment with a preceding blank line int field; ¶ // another comment ... } |
|
See also: | Jindent - Settings - Formatter - C / C++ - Comments - Blank Lines , Jindent - Settings - Formatter - C / C++ - Blank Lines |
| If number of lines in body is at least ... then insert blank line after { |
|
class MyClass : public MyOtherClass { String getString() { callMethodA(); callMethodB(); return callMethodC(); } } ¶ struct MyStruct { int x; } |
MyStruct looks fine,
but class MyClass : public MyOtherClass seems to be formatted too close:
The class head class MyClass : public MyOtherClass { and the first method declaration
String getString() { are connected too close and could cause confusion.
|
class MyClass : public MyOtherClass { ¶ String getString() { callMethodA(); callMethodB(); return callMethodC(); } } ¶ struct MyStruct { int x; } |
MyClass seems to be much clearer and
struct MyStruct is still formatted as before.|
class MyClass : public MyOtherClass { ¶ String getString() { callMethodA(); callMethodB(); return callMethodC(); } } ¶ struct MyStruct { ¶ int x; } |
infinite.| If number of lines in body is at least ... then insert blank line before } |
|
class MyClass : public MyOtherClass { ¶ String getString() { callMethodA(); callMethodB(); return callMethodC(); ¶ } ¶ struct MyStruct { int x; } |
| Do not insert blank line before single left brace |
|
See also: | Jindent - Settings - Formatter - C / C++ - Braces Style - Presets |