Ubuntu 中的"int"

"int" in Ubuntu

本文关键字:int 中的 Ubuntu      更新时间:2023-10-16

有人能告诉我,在编译c++程序时,g++(Ubuntu/Linaro 4.4.4-14ubuntu5(4.4.5是否将ints更改为long ints吗?如果是这样的话,该如何改变呢?如果没有,我只是超载operator long吗?它是否就像重载运算符uint32_t/uint64_t一样?这似乎是一种不同类型的打字(并非双关语(。

这导致了错误:

uint128_t.h: In function ‘std::ostream& operator<<(std::ostream&,
uint128_t)’:
uint128_t.h:593: error: conversion from ‘uint128_t’ to ‘long int’ is
ambiguous
uint128_t.h:83: note: candidates are: uint128_t::operator uint64_t()
uint128_t.h:79: note:                 uint128_t::operator uint32_t()
uint128_t.h:75: note:                 uint128_t::operator uint16_t()
uint128_t.h:71: note:                 uint128_t::operator uint8_t()
uint128_t.h:67: note:                 uint128_t::operator int()
uint128_t.h:63: note:                 uint128_t::operator char()
uint128_t.h:59: note:                 uint128_t::operator bool()

试试这个变体:

out = "0123456789abcdef"[size_t(rhs % div)] + out;

因为您已经提供了对所有无符号类型的转换,但没有提供对有符号int.的转换


是的,您可以定义一个到long int的隐式转换,只需以与所有其他转换相同的方式定义operator long即可。


最后,请注意,您选择的结构名称由POSIX保留,并且可能与标准库头stdint.h的未来版本冲突。

不,不是。int就是int就是int。它是一个独立于long int的类型。至于您重载了哪些运算符,这完全取决于您想做什么。你还没有真正描述过。

但是,如果您想定义一个运算符来处理int,那么您应该为int重载它。如果您希望它在long int上工作,请为此定义一个重载。

你想干什么?为什么要将uint128_t传递给操作员,却询问intlong int