Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > how to Specializations of function Templates or Overloading Function templates with Templates ?

Reply
Thread Tools

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

 
 
recover
Guest
Posts: n/a
 
      07-25-2006

#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£º
MSN:
Com.£º http://www.lingtu.com/
http://www.51ditu.com/
--------------------------


 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      07-25-2006
recover wrote:
> [..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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
 
recover
Guest
Posts: n/a
 
      07-25-2006
Thanks.


>
> Please, PLEASE, throw that compiler away. Get yourself something
> decent. Luckily, there are several free ones available.
>
> V
> --
> Please remove capital 'A's when replying by e-mail
> I do not respond to top-posted replies, please don't ask
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Overloading __init__ & Function overloading Iyer, Prasad C Python 3 09-30-2005 02:17 PM
Re: Overloading __init__ & Function overloading Steve Holden Python 0 09-30-2005 01:58 PM
Re: Overloading __init__ & Function overloading Fredrik Lundh Python 0 09-30-2005 01:53 PM
Templates Specializations for Event-Driven Programming christopher diggins C++ 4 12-21-2004 06:42 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57