[英]ambiguous call to overloaded function for time_t and int64
I am getting following error 我收到以下错误
1>------ Build started: Project: test123, Configuration: Debug Win32 ------
1> test.cpp
1>e:\avinash\test123\test.cpp(25): error C2668: 'XYZ::createKey' : ambiguous call to overloaded function
1> e:\avinash\test123\test.cpp(13): could be 'void *XYZ::createKey(const int64_t)'
1> e:\avinash\test123\test.cpp(7): or 'void *XYZ::createKey(const time_t &)'
1> while trying to match the argument list '(long)'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Following is the source code, how do i solve this 以下是源代码,我该如何解决
#include <WinSock2.h>
typedef signed __int64 int64;
typedef int64 int64_t;
namespace XYZ
{
inline void* createKey( const time_t& value ) {
return NULL;
}
inline void* createValue( const time_t& value ) {
return NULL;
}
inline void* createKey(const int64_t value) {
return NULL;
}
inline void* createValue(const int64_t value) {
return NULL;
}
}
int main( int argc, char** argv)
{
XYZ::createKey(10L);
return 0;
}
time_t
is __int64
on your platform. time_t
在您的平台上是 __int64
。 It might be long
or int
on other platforms. 在其他平台上可能是
long
或int
。 There is no way to define separate overloads for time_t
and the primitive integer type it aliases, because it is not a separate type . 无法为
time_t
及其别名的原始整数类型定义单独的重载,因为它不是单独的类型 。
The overloads above are pointless. 上面的重载是没有意义的。 The compiler won't change them based on whether the argument is declared
time_t
or __int64
but based on whether the argument is a const reference or not (if I read the specification correctly the reference is a worse match for anything except exactly the same reference type than the non-reference, but I am not sure about it by far). 编译器不会根据参数是否声明为
time_t
或__int64
更改它们,而是基于参数是否为const引用(如果我正确地阅读了规范,则该引用对于除完全相同的引用类型之外的任何内容都更差)比非参考文献更重要,但我目前还不确定)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.