我有一个关于 C++ 初始化列表消歧的问题,它在 gcc、clang 和 Visual Studio 之间表现出不同的行为。
我想知道这是“未定义的行为”(不正确的程序)还是这些编译器之一有错误。任何的想法?
考虑以下声明:
class Arg
{
public:
Arg(int i);
};
class Object
{
public:
Object(const char* str, int i);
Object(const char* str, const std::initializer_list<Arg>& args);
};
Run Code Online (Sandbox Code Playgroud)
现在这种用法:
Object c("c", {4});
Run Code Online (Sandbox Code Playgroud)
应该使用哪个构造函数?一个 with int(假设文字周围的大括号是多余的)或一个带有初始化列表的(隐式转换 from intto Arg)。
GCC 10.2.0 选择具有初始化列表的构造函数Arg。
Clang 11.2.2-2 选择构造函数int并报告有关大括号的警告:
initlist.cpp:46:19: warning: braces around scalar initializer [-Wbraced-scalar-init]
Object c("c", {4});
^~~
Run Code Online (Sandbox Code Playgroud)
Visual Studio 2019 16.8.6 选择int没有警告的构造函数( /W4)。
从多数人的角度来看,具有int胜利的构造函数。另一方面,如果我们直接使用std::initializer_list<int> …
如何在 ARM64 系统上原生构建适用于 ARM64 的 Windows 11 设备驱动程序?
使用:
我有一个适用于 Windows 11 的简单 WDM 驱动程序。
在 ARM64 上构建相关的用户态应用程序。只有驱动程序无法构建。
构建错误消息是
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(442,5):
error MSB8020: The build tools for WindowsKernelModeDriver10.0 (Platform Toolset = 'WindowsKernelModeDriver10.0') cannot be found.
To build using the WindowsKernelModeDriver10.0 build tools, please install WindowsKernelModeDriver10.0 build tools.
Alternatively, you may …Run Code Online (Sandbox Code Playgroud)