更新 Visual Studio 2017,现在出现编译错误 C7510:"回调":使用依赖模板名称必须以 'template' 为前缀

Update visual studio 2017, now getting compile error C7510: 'Callback': use of dependent template name must be prefixed with 'template'

本文关键字:前缀 template 2017 Studio Visual 编译 更新 回调 C7510 错误 依赖      更新时间:2023-10-16

更新后,我尝试像往常一样编译我的项目(15.8.0(。 我将 showinclude 设置为 yes 以找出错误的来源,但这都是系统代码。 从 stdafx.cpp 开始,它会遍历所有包含和错误:

1>Note: including file:     C:Program Files (x86)Windows Kits10Include10.0.17134.0sharedpshpack8.h
1>Note: including file:     C:Program Files (x86)Windows Kits10Include10.0.17134.0sharedpoppack.h
1>Note: including file:    C:Program Files (x86)Windows Kits10Include10.0.17134.0sharedpshpack8.h
1>Note: including file:    C:Program Files (x86)Windows Kits10Include10.0.17134.0sharedpoppack.h
1>Note: including file:   C:Program Files (x86)Windows Kits10Include10.0.17134.0winrtwrlevent.h
1>Note: including file:    C:Program Files (x86)Windows Kits10Include10.0.17134.0winrteventtoken.h
1>Note: including file:    C:Program Files (x86)Windows Kits10Include10.0.17134.0sharedpshpack8.h
1>c:program files (x86)windows kits10include10.0.17134.0winrtwrlevent.h(316): error C7510: 'Callback': use of dependent template name must be prefixed with 'template'
1>c:program files (x86)windows kits10include10.0.17134.0winrtwrlevent.h(324): error C7510: 'Callback': use of dependent template name must be prefixed with 'template'

以前有人见过这个吗? 我上下搜索以找到答案无济于事。 除了修改Windows SDK之外,不知道该怎么做。

编辑: 在我安装的 windows SDK 中,错误出在文件中

-C:\Program Files (x86(\Windows Kits\10\Include\10.0.17134.0\winrt\wrl\event.h

更改了第 316 行:返回委托助手::特征::回调(详细信息::转发(回调((;

to:返回委托助手::特征::模板回调(详细信息::转发(回调((;

第 324 行:返回委托助手::特征::回调(

返回委托助手::特征::模板回调(详细信息::转发(回调((;

由于修改 sdk 并不是真正的解决方案,因此 Peng Du 的解决方案是在配置窗口中选择不符合项。

我有遗留项目,我并排比较了项目设置,最后我通过设置成功构建了新项目:Configuration Properties>C/C++>Language>Conformance mode = No

使用依赖模板名称时,必须使用template关键字,例如:

foo.template bar<T>();

直到某个时候,MSVC 对使用typenametemplate消除歧义器并不严格,但在更新后,规则发生了变化。

问题出在Windows运行时库中,对Visual Studio的一些更改破坏了它。我在这台更新到 15.8.2 的笔记本电脑上遇到了同样的问题,我家里运行早期版本的机器不会这样做,因为完全相同的代码在我的另一台机器上编译,它一定是 VS 中的错误,或者 WRL/event 类中需要更改。

编辑:修复了上面的返回值,错误在SDK中,你不应该禁用/permissive-因为这可以防止Spectre和其他安全增强功能。