1

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;
}
Avinash
  • 12,851
  • 32
  • 116
  • 186
  • 3
    According to MSDN documentation, `time_t` is either `long` or `__int64`. Does it let you declare both overloads if they both took the parameter by value? – Angew is no longer proud of SO Mar 13 '13 at 07:39
  • http://stackoverflow.com/questions/471248/what-is-ultimately-a-time-t-typedef-to put some ligt on time_t typedef – Saqlain Mar 13 '13 at 07:56
  • What do you want to use those overloads for? You can't have them, but if you said what is your goal, somebody could advise you how to achieve it by different means. – Jan Hudec Mar 13 '13 at 09:58

1 Answers1

1

time_t is __int64 on your platform. It might be long or int on other platforms. 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.

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

Jan Hudec
  • 73,652
  • 13
  • 125
  • 172
  • Then how would I handle then If i want to do specific to time_t, any suggestion. – Avinash Mar 13 '13 at 10:11
  • @Avinash: `time_t` **does not exist**. It is just another name for some integral type. _What specific thing do you want to do with it_? – Jan Hudec Mar 13 '13 at 10:16