我从这篇文章中学到了在命名空间中创建辅助函数。 'Helper'在C ++中的功能
//stringhelper.hpp namespace utility{ static std::string intToString(int integer) { std::stringstream sstream; sstream << integer; return sstream.str(); } static void toLowerCase(std::string& y) { std::transform(y.begin(), y.end(), y.begin(), (int(*)(int))tolower); } }我包含此标题但我收到以下警告
'void utility::toLowerCase(std::string&)' defined but not used是。 我使用intToString(int integer)但不使用toLowerCase(std :: string&)。 我不希望看到那些警告或每个标题分配一个辅助函数。
有谁能建议一个好的解决方案? 我应该禁用警告吗? 谢谢
I learnt from this post here to create helper functions in namespace. 'Helper' functions in C++
//stringhelper.hpp namespace utility{ static std::string intToString(int integer) { std::stringstream sstream; sstream << integer; return sstream.str(); } static void toLowerCase(std::string& y) { std::transform(y.begin(), y.end(), y.begin(), (int(*)(int))tolower); } }I include this header but I got the following warning
'void utility::toLowerCase(std::string&)' defined but not usedYes. I used intToString(int integer) but not toLowerCase(std::string&). I don't want to see those warning or divide one helper function per header.
Can anyone suggest a good solution? Should I just disable warning? Thank you
最满意答案
您可以选择关闭该警告:
-Wno-unused-function在逐个函数的基础上,使用GCC,您可以定义:
void whatever () __attribute__ ((unused)); void whatever () { stuff; }这告诉GCC该函数可能未被使用。
有关属性的更多信息,请参阅编译器文档
You have the option to turn off that warning:
-Wno-unused-functionOn a function-by-function basis, with GCC, you may define:
void whatever () __attribute__ ((unused)); void whatever () { stuff; }This tells GCC that the function is meant to possibly be unused.
See compiler docs for more info on attribute
更多推荐
发布评论