简体   繁体   中英

“int” in Ubuntu

Can anyone tell me if, when compiling a c++ program, does g++ (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5 change int s to long int s? if so, how can this be changed? If not, do I just overload operator long ? Is it just like overloading operator uint32_t/uint64_t? It seems like a different type of typecasting (no pun intended).

this is causing the errors:

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()

No, it doesn't. An int is an int is an int. It's a separate type from long int . As for which operators you overload, it depends entirely on what you want to do . You haven't really described that.

But if you want to define an operator to work on int , then you should overload it for int . If you want it to work on long int , define an overload for that.

What are you trying to do? And why are you passing a uint128_t to the operator, but asking about int and long int ?

Try this variation:

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

since you've provided conversions to all manner of unsigned types, but not to signed int.


And yes, you can define an implicit conversion to long int just be defining operator long in the same manner as all the other conversions.


Finally, please note that your choice of structure name is reserved by POSIX, and likely to conflict with future versions of the standard library header stdint.h .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM