对time_t和int64的重载函数进行模糊调用

时间:2013-03-13 07:31:14

标签: c++

我收到以下错误

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 ==========

以下是源代码,我该如何解决这个问题

#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;
}

1 个答案:

答案 0 :(得分:1)

您平台上的

time_t __int64。在其他平台上可能是longint无法time_t定义单独的重载以及别名的原始整数类型,因为不是单独的类型

上述重载毫无意义。编译器不会根据参数是声明time_t还是__int64来更改它们,而是根据参数是否为const引用(如果我正确读取规范,则引用更差)除了与非引用完全相同的引用类型之外的任何内容,但到目前为止我还不确定。

相关问题