快捷搜索: 王者荣耀 脱发

C2872 “byte“ 不明确的符号 编译报错

编译器为MSVC2019

原因:

参考:

具体如下:

std::byte ambiguous symbol and rpcndr.h There is actually a conflict between C++17 and one Windows header.

The precursor is that using namespace std; is used before #include <Windows.h>, and there will be a conflict in the ancient header rpcndr.h about the definition of a byte.

1>c:program files (x86)windows kits10include10.0.16299.0shared pcndr.h(192): error C2872: ‘byte’: ambiguous symbol std::byte is a new type in C++17, and different than the usual definition of a byte. CPP Reference has more detailed information about std::byte. In the ancient header, a byte is defined as typedef unsigned char byte;. This conflicts with the C++17 definition of a byte, being enum class byte : unsigned char { };.

For Visual Studio, this behavior can be turned off by defining the preprocessor value _HAS_STD_BYTE to 0.

意思是大概是:由于版本原因,当using namespace std;之前没有#include <windows.h>的话,就会存在这个编译error

解决方法:

  1. 不使用using namespace std;
  2. 在使用using namespace std;前#include <windows.h>
经验分享 程序员 微信小程序 职场和发展