请参阅Visual Studio 2019中捕获std::exception时函数模板实例化消息的参考 我注意到VisualStudio 2019,Windows 10中C++控制台应用程序的构建过程中有一个恼人的消息。我有一个生成消息的模板函数: message : see reference to function template instantiation 'int run_loop<wchar_t>(int,const char_type *[])' being compiled with [ char_type=wchar_t ]

请参阅Visual Studio 2019中捕获std::exception时函数模板实例化消息的参考 我注意到VisualStudio 2019,Windows 10中C++控制台应用程序的构建过程中有一个恼人的消息。我有一个生成消息的模板函数: message : see reference to function template instantiation 'int run_loop<wchar_t>(int,const char_type *[])' being compiled with [ char_type=wchar_t ],c++,windows,compiler-warnings,C++,Windows,Compiler Warnings,我的环境: 操作系统:Windows 10 Pro x64版本1909操作系统构建18363.836 IDE:Visual Studio 2019版本16.6.0 C++中的Win32控制台应用程序模板,默认设置为: Windows SDK版本:10.0 平台工具集:Visual Studio 2019(v142)此编译器消息并不代表它自己,它伴随着另一条消息。给定您的代码,完整的输出是 警告C4100:“argv”:未引用的形式参数 消息:请参阅正在编译的函数模板实例化“int run_lo

我的环境:

操作系统:Windows 10 Pro x64版本1909操作系统构建18363.836

IDE:Visual Studio 2019版本16.6.0

C++中的Win32控制台应用程序模板,默认设置为:

Windows SDK版本:10.0


平台工具集:Visual Studio 2019(v142)

此编译器消息并不代表它自己,它伴随着另一条消息。给定您的代码,完整的输出是

警告C4100:“argv”:未引用的形式参数
消息:请参阅正在编译的函数模板实例化“int run_loop(int,const char_type*[])”

[
char\u type=wchar\u t
]

因此,主要信息是警告
argv
是未引用的形式参数。编译器会向您提供一个附加提示,提示您如何实例化模板。如果一个模板有多个实例化,并且仅在某些实例化中出现警告,那么这将非常有用


顺便说一句,修复该警告后,您仍然会收到相同的消息,因为
argc
ex
也未使用。删除所有三个名称或使用它们后,您将不再收到警告和消息。

这一行不是错误,而是编译器的一部分。出现在上面几行的错误或警告解释问题的根源在于您对术语“模板功能”的使用。您真正拥有的是一个“函数模板”,它需要实例化以生成代码。这种误解使您无法理解代码和错误消息。修那块手表沃尔特·E·布朗的演讲。是的,谢谢!当我引用argc、argv和ex时,消息消失了<如果不用于抑制消息,则代码>常量std::exception&ex也可以替换为
常量std::exception&
#include <exception>

template<class char_type>
int run_loop(int argc, const char_type* argv[])
{
    try
    {
    }
    catch (const std::exception& ex)
    {
    }

    return 0;
}

int wmain(int argc, const wchar_t* argv[])
{
    return run_loop(argc, argv);
}