我有一些重載函數,但在我的測試代碼中產生了一些錯誤。重載函數產生模糊錯誤
inline void tt(uint8_t& v) { }
inline void tt(int8_t& v) { }
inline void tt(char& v) { }
inline void tt(uint16_t& v) { }
inline void tt(int16_t& v) { }
inline void tt(uint32_t& v) { }
inline void tt(int32_t& v) { }
inline void tt(uint64_t& v) { }
inline void tt(int64_t& v) { }
int main(int argc, char* argv[]) {
unsigned char t1;
signed char t2;
unsigned short t3;
short t4;
unsigned int t5;
int t6;
unsigned long t7;
long t8;
char t9;
tt(t1); // ok
tt(t2); // ok
tt(t3); // ok
tt(t4); // ok
tt(t5); // ok
tt(t6); // ok
tt(t7); // error
tt(t8); // error
tt(t9); // ok
}
爲什麼所有工作除(無符號)長?看在standard長是至少(像所有其他類型)32位。
There are five standard signed integer types: 「signed char」, 「short int」, 「int」, 「long int」, and 「long long int」. In this list, each type provides at least as much storage as those preceding it in the list.
我可以通過插入
inline void tt(unsigned long int& v) { }
inline void tt(long int& v) { }
到代碼避免這種情況。我只想知道爲什麼這個演員不行。
1)這絕對不是標準。 [試試這個](http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2012/n3485.pdf)。 2)您沒有閱讀表格下方的註釋。官方至少有32位。 – chris
@CaptainObvlious我試過了,但它也不起作用。 – user1810087