views:

54

answers:

2

When i write a classes constructor typing : to start the initialization list of a C++ constructor Visual Studio indents the line when it is right after a namespace directive. Also when i type :: (scope resolution) Visual Studio indents the line, which i found very annoying since the indentation was correct in the first place and i always have to undo Visual Studio's indentation.

Example:

This is what i haved typed:

namespace XY {

MyClass::MyClass()

now i type <space>:, and VS indents:

namespace XY {

     MyClass::MyClass() :

which is not what i, uh, intended.

This behaviour is - strictly speaking - correct, according to the rules of the "Smart Indenting" option of MSVC. But in this context it is not what I want.

Is there a way to turn off smart indenting in this context? I suppose that it is a quite common style not to indent namespace blocks.

A: 

The reason for this is behaviour is the preceding namespace directive:

namespace XY {

MyClass::MyClass() 

So MSVC wants to indent the constructor definition.

Mea culpa.

Wolfgang Plaschg
I'd hardly say it's your fault. You've found the cause, but the main question is still unanswered. How do you *disable* that indentation?
Rob Kennedy
@Wolfgang: This should be an edit to your OP, not an answer to it.
John Dibling
@John Dibling: Thanks for the hints, I restated my question
Wolfgang Plaschg
+1  A: 

This is for VS9: Go to Tools>Options>Text Editor>C/C++>Tabs. Under Indenting "Smart" will probably be selected. Select "None" and you are bingo.

John Dibling