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 kits\10\include\10.0.16299.0\shared\rpcndr.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>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wow_awsl_qwq

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值