如何避免帮助函数被警告?(How to avoid helper functions being warned? “ xxx defined but not used”)

编程入门 行业动态 更新时间:2024-10-28 16:25:15
如何避免帮助函数被警告?(How to avoid helper functions being warned? “ xxx defined but not used”)

我从这篇文章中学到了在命名空间中创建辅助函数。 '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 used

Yes. 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-function

On 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

更多推荐

本文发布于:2023-08-05 04:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1428500.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   helper   avoid   functions   xxx

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!