Eclipse-CDT:在自动生成的包含防护中使用命名空间
是否可以(以及如何)在 Eclipse CDT,在使用 .hpp/.cpp 模板创建新类时?
Is it possible (and how) to add the namespace in the name of the automatic generated include guards in Eclipse CDT, when creating a new class using the .hpp/.cpp templates?
对我来说,Eclipse 很好地生成了一个带有命名空间的新类,但是包含保护不包含命名空间,所以如果同一个头文件在两个不同的目录中存在两次,则只能包含一个.
For me Eclipse generates a new class with a namespace nicely, but the include guards do not contain the namespace, so if the same header file exists twice in two different directories, only one can be included.
在我的例子中,命名空间的名称、Eclipse 项目名称和源目录的名称都是相同的,因此这些可以作为包含保护的前缀的替代方案.
In my case the name of the namespace, the Eclipse project name and the name of the source directory are all the same, so these could be alternatives as prefix for the include guard.
推荐答案
所以在 C/C++ -> Code Style -> Code Templates 下的 Preferences 对话框中,您可以修改模板以更接近您的需要,例如,如果你需要守卫中的命名空间,你可以做类似的事情.
So in the Preferences dialog under C/C++ -> Code Style -> Code Templates you can modify the template to be closer to what you need, for example if you need the namespace in the guard, you can do something like.
${filecomment}
#ifndef ${namespace_name}_${include_guard_symbol}
#define ${namespace_name}_${include_guard_symbol}
${includes}
${namespace_begin}
${declarations}
${namespace_end}
#endif /* ${namespace_name}_${include_guard_symbol} */`
相关文章