我的项目中有以下代码:
class RangeConverter {
private:
struct Converter {
double MinimumInput;
double MaximumInput;
double MinimumOutput;
double MaximumOutput;
template <typename RangeType>
RangeType Convert ( RangeType invalue ) const {
double v = static_cast<double> ( invalue );
if ( v < MinimumInput ) {
v = MinimumInput;
} else if ( v > MaximumInput ) {
v = MaximumInput;
}
double interpolationfactor = ( v - MinimumInput ) / ( MaximumInput - MinimumInput );
return static_cast<RangeType> ( ( interpolationfactor * ( MaximumOutput - MinimumOutput ) ) + MinimumOutput );
}
};
.....
使用 AStyle 格式化该代码后,我得到以下信息:
class RangeConverter {
private:
struct Converter {
ngeConverter {
private:
struct Converter {
double MinimumInput;
double MaximumInput;
double MinimumOutput;
double MaximumOutput;
template <typename RangeType>
RangeType Convert ( RangeType invalue ) const {
double v = static_cast<double> ( invalue );
if ( v < MinimumInput ) {
v = MinimumInput;
} else if ( v > MaximumInput ) {
v = MaximumInput;
}
double interpolationfactor = ( v - MinimumInput ) / ( MaximumInput - MinimumInput );
return static_cast<RangeType> ( ( interpolationfactor * ( MaximumOutput - MinimumOutput ) ) + MinimumOutput );
}
};
.....
astyle 命令:
astyle
\ --style=java
\ --indent=force-tab=2
\ --indent-classes
\ --indent-switches
\ --indent-labels
\ --indent-preprocessor
\ --indent-col1-comments
\ --pad-oper
\ --pad-paren
\ --delete-empty-lines
\ --add-brackets
\ --align-pointer=type
\ --align-reference=type
这是风格的错误,还是我忘记了任何选择?如果它是一个错误,你会建议用 VIM 格式化 C++ 代码吗?