473,569 Members | 2,400 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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


#include <stdio.h>

template<class T>
class TpHello
{
public:
int GetHash(){retur n 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 <Tkey)
{
return key.GetHash();
}

int main()
{
TpHello<inttpIn t;
HashKey(tpInt);
return 0;
}
compile error in VC6
--------------------Configuration: template - Win32
Debug--------------------
Compiling...
template.cpp
E:\work\hellote st\template.cpp (52) : error C2667: 'HashKey' : none of 2
overload have a best conversion
E:\work\hellote st\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£ºzh******* ***@lingtu.com
MSN: re********@hotm ail.com
Com.£º http://www.lingtu.com/
http://www.51ditu.com/
--------------------------
Jul 25 '06 #1
2 1577
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
Jul 25 '06 #2
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


Jul 25 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
6457
by: Dave Theese | last post by:
Hello all, I'm trying to get a grasp of the difference between specializing a function template and overloading it. The example below has a primary template, a specialization and an overload. Note that the overload is identical to the specialization except, of course, for the missing "template <>". I don't know if my questions will be a...
7
1990
by: Hendrik Schober | last post by:
Hi, I have a problem, that boils down to the following code: #include <iostream> #include <typeinfo> class Test1 {}; class Test2 {}; class Test3 {};
4
1828
by: CoolPint | last post by:
I would be grateful if someone could point out if I am understanding correctly and suggest ways to improve. Sorry for the long message and I hope you will kindly bear with it. I have to make it elaborate to make sure my questions are clear enough. Let's say I need to write a function whose logic is same for all types (T) except in the case...
1
1623
by: Samee Zahur | last post by:
Why aren't we allowed to do partial specializations like these on numeric template parameters? That would have allowed us to do all kinds of interesting stuffs like loops of variable nesting (bad practice though - I Know) and lots of other things!g++ even knows that it is a partial specialization I am aiming for ... but it just won't allow...
16
16223
by: WittyGuy | last post by:
Hi, What is the major difference between function overloading and function templates? Thanks! http://www.gotw.ca/resources/clcm.htm for info about ]
22
5973
by: Ian | last post by:
The title says it all. I can see the case where a function is to be called directly from C, the name mangling will stuff this up. But I can't see a reason why a template function can't be given extern "C" linkage where it is to be assigned to a C function pointer. Ian
9
1584
by: Hendrik Schober | last post by:
Hi, this code #include <iostream> template< typename T > struct X { void f(); };
39
2192
by: zeus | last post by:
I know function overloading is not supported in C. I have a few questions about this: 1. Why? is it from technical reasons? if so, which? 2. why wasn't it introduced to the ANSI? 3. Is there any C implementation supporting this feature? I assume some of you will claim that there is no need in function overloading, so I would like to know...
6
2755
by: wkaras | last post by:
I tried a couple of compilers, and both gave errors compiling this: template <bool fin, typename T> T foo(T val); template <typename T> T foo<true, T>(T val) { return(val); } But both gave no errors compiling this:
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.