我有一大堆的重载所有[u]int{8|16|32|64}_t
类型的函数:“长unsigned int类型”为“uint32_t的”暧昧呼叫
std::string f(uint8_t) { /*something*/ }
std::string f( int8_t) { /*something*/ }
std::string f(uint16_t) { /*something*/ }
std::string f(int16_t) { /*something*/ }
std::string f(uint32_t) { /*something*/ }
std::string f(int32_t) { /*something*/ }
std::string f(uint64_t) { /*something*/ }
std::string f(int64_t) { /*something*/ }
//A few more overloads with a few more types (bool, float, const char*, etc.)
我现在调用该函数的名称与long unsigned int
类型的参数:
template <typename type_blah> class Something { public:
//...
std::string call_f(void) const {
return f(*((type_blah*)(internal_variable)));
}
//...
};
这产生一个错误:
error: call of overloaded 'f(long unsigned int&)' is ambiguous
我想这会发生,因为unsigned int
和uint32_t
是不同的类型。但是,我不能为long unsigned int
更多地重载函数,因为这是一个冗余定义。 I.e .:
std::string f(long unsigned int) { /*something*/ }
。 。 。生产:
error: 'std::string f(uint32_t)' previously defined here
看来类机构对彼此的工作:它无法弄清楚要使用的转换,因为每次转换都同样有效,但无转换超载不能因为它已经被定义了。
由于各种原因,我无法施展参数。有没有办法呢?
平台是在Windows 7 x86-64上运行的g ++ MinGW x86。
能你请[SSCCE](http://sscce.org/)向我们展示?或者至少是函数声明和你如何调用它? –
你使用的编译器有32位的“long”吗? –
@MatsPetersson:我不确定这可以解释它。假设OP按照他的说法创建了重载,那么'f(some_unsigned_long)'应该完全匹配至多一个重载。 –