how to Specializations of function Templates or Overloading Function templates with Templates ?

R

recover

#include <stdio.h>

template<class T>
class TpHello
{
public:
int GetHash(){return 0;}
protected:
private:
T a;
};

template<class T>
int HashKey(T key)
{
return (int)key;
}

//Specializations of function Templates or Overloading Function templates
template<class T>
int HashKey(TpHello<T> key)
{
return key.GetHash();
}

int main()
{
TpHello<int> tpInt;
HashKey(tpInt);
return 0;
}


compile error in VC6
--------------------Configuration: template - Win32
Debug--------------------
Compiling...
template.cpp
E:\work\hellotest\template.cpp(52) : error C2667: 'HashKey' : none of 2
overload have a best conversion
E:\work\hellotest\template.cpp(52) : error C2668: 'HashKey' : ambiguous call
to overloaded function
Error executing cl.exe.

template.exe - 2 error(s), 0 warning(s)

--
= = = = = = = = = = = = = = = = = = = = = =

¡¡¡¡¡¡¡¡¡¡¡¡¡¡
zhang
----------------------------
Co.: beijing lingtu
Ad.: beijing zpart
ZIP£º 100094
Mail£º[email protected]
MSN: (e-mail address removed)
Com.£º http://www.lingtu.com/
http://www.51ditu.com/
--------------------------
 
V

Victor Bazarov

recover said:
[..valid code redacted..]


compile error in VC6
[..]

Please, PLEASE, throw that compiler away. Get yourself something
decent. Luckily, there are several free ones available.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top