How to use GCC diagnostic pragma with C++ template functions?

不羁岁月 提交于 2019-12-03 16:22:27

The issue is that the instantiation of the template is compiled when you use it, not when it is parsed by the compiler in the header file so it will not issue the warning until it replaces T by int and parses it as a regular function outside the context of the pragma silencing.

The usual way to indicate that you don't intend to use a parameter is to not give it a name:

template<typename T> 
int mytemplatefunc(T /* t */) 
{ return 42; } 

int mystandardfunc(int /* i */) 
{ return 53; } 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!