c++ - c++11 unsigned char becoming int when using operator =
问题描述
c++11 unsigned char becoming int when using operator =, example code below:
#include <iostream>
int main(int argc, char* argv[]) {
class uchar {
public:
uchar(unsigned char c)
: c_(c) {
}
private:
unsigned char c_;
};
const unsigned char c2 = 5;
uchar c1(5);
// output: 1 1
std::cout << sizeof(c1) << " " << sizeof(c2) << std::endl;
// compile error: invalid operands to binary expression ('uchar' and 'int')
std::cout << (c1 == c2) << std::endl;
}
can somebody explain why the above error? why does clang report c2
as an int?
using clang++ v6.0 -std=c++11
解决方案
推荐阅读
- python - 在 Google Contacts API 调用中获取照片
- php - 我无法在我的个人 html 代码和 php 代码中显示我的朋友列表
- php - 如何基于多用户系统的防护将用户重定向到不同的页面?
- redis - 如何从redis位图中获取二进制字符串?
- javascript - 使用 requestanimationframe,分析显示 >80% 的时间花费在空闲上,仍然获得 4fps。为什么?(/怎么修?)
- p5.js - 如何在 p5.js 中执行操作步骤
- java - 在java中将字符串(日期)转换为毫秒时遇到困难
- javascript - AngularJS - 向服务器发送一个 dom 元素
- sql-server - SQL Server Management Studio - 文本选项的列约束
- vb.net - VB.NET 在函数调用中修改位图