Eclipse-CDT:在自动生成的包围守卫中使用命名空间 [英] Eclipse-CDT: Use Namespace in automatic generated include-guards

查看:238
本文介绍了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项目名称和源目录的名称都是一样的,所以这些可以替代为include guard的前缀。

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 ++ - >代码样式 - >代码模板下的首选项对话框中,您可以将模板修改为更接近所需的模板,例如,如果您需要保护的命名空间,可以做某事。

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} */`

这篇关于Eclipse-CDT:在自动生成的包围守卫中使用命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆