問題描述
是否可以(以及如何)在 Eclipse CDT,在使用 .hpp/.cpp 模板創(chuàng)建新類時?
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 對話框中,您可以修改模板以更接近您的需要,例如,如果你需要守衛(wèi)中的命名空間,你可以做類似的事情.
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} */`
這篇關(guān)于Eclipse-CDT:在自動生成的包含防護中使用命名空間的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!