Eclipse:评论整个代码而不会被另一条评论缩短

Sva*_*sky 4 c++ eclipse comments block-comments

假设我有以下代码(在C++中,但这对问题可能并不重要):

int main() {
    ....random code....
    /*This is a comment*/
    ....random code....
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

在eclipse中,当我想通过在代码之前和之后放入/*和*/来注释掉整个代码时,注释会在第3行的"这是注释"的末尾被*/缩短,所以其余代码未被注释.

/*    //<--overall comment starts here
int main() {
    ....random code....
    /*This is a comment*/    //<--overall comment ends here
    ....random code....
    return 0;
}
*/  //<--overall comment SHOULD end here
Run Code Online (Sandbox Code Playgroud)

任何人都知道解决这个问题的方法,或者我只需处理它或使用//评论......?

vso*_*tco 6

在C++中没有办法嵌套注释.一种解决方案(特别是如果你不想改变很多/* *///)是使用预处理器,你可以这样做

#ifdef SOME_RANDOM_SYMBOL

code that you want to comment here

#endif
Run Code Online (Sandbox Code Playgroud)

只是确保SOME_RANDOM_SYMBOL在代码中没有以某种方式定义.

正如@Caleb在评论中提到的,你也可以这样做

#if 0

code that you want to comment here

#endif
Run Code Online (Sandbox Code Playgroud)

但使用符号可以搜索它.