Click here to Skip to main content
15,886,919 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: template function v.s. template class PinPopular
CPallini12-Dec-07 21:10
mveCPallini12-Dec-07 21:10 
GeneralRe: template function v.s. template class Pin
George_George12-Dec-07 21:46
George_George12-Dec-07 21:46 
QuestionOff-topic Pin
CPallini12-Dec-07 21:54
mveCPallini12-Dec-07 21:54 
JokeRe: Off-topic Pin
Cedric Moonen12-Dec-07 22:03
Cedric Moonen12-Dec-07 22:03 
JokeRe: Off-topic Pin
CPallini12-Dec-07 22:10
mveCPallini12-Dec-07 22:10 
GeneralRe: Off-topic Pin
George_George12-Dec-07 22:34
George_George12-Dec-07 22:34 
GeneralRe: Off-topic Pin
George_George12-Dec-07 22:35
George_George12-Dec-07 22:35 
GeneralRe: template function v.s. template class Pin
Cedric Moonen12-Dec-07 21:19
Cedric Moonen12-Dec-07 21:19 
I suppose that you were asking about something like this (in which case your example is very badly chosen because you specify explicitely the type):

template <class T>
void myTemplateFunc(T arg)
{
// some code here
}


And to use it, you do something like this:
int myValue = 42;
myTemplateFunc(myValue);


But, in fact even in that case there is no matching involved. The compiler will simply 'generate'a new function and replace T by an integer. Now if you call that function and supply a float, then the compiler will generate a second function and replace T by a float. You have to look at templates as code that will be generated by the compiler once you use the template (be it a class or a function). And if you call your function with two different types, then two different functions will be generated.

The only case where a matching is done, is when you use template specialization (if I provide a version of my function specifically for float for example). In that case, the compiler will try to find the best match. But in general, the compiler is quite intelligent to solve the problem on its own.


Cédric Moonen
Software developer

Charting control [v1.2]

GeneralRe: template function v.s. template class Pin
George_George12-Dec-07 21:45
George_George12-Dec-07 21:45 
Generalanother day, another series of dumbass questions... Pin
toxcct12-Dec-07 23:16
toxcct12-Dec-07 23:16 
GeneralCan anyone explain me... Pin
Nelek13-Dec-07 0:39
protectorNelek13-Dec-07 0:39 
GeneralRe: Can anyone explain me... Pin
George_George13-Dec-07 0:43
George_George13-Dec-07 0:43 
GeneralRe: Can anyone explain me... [modified] Pin
toxcct13-Dec-07 3:10
toxcct13-Dec-07 3:10 
QuestionHelp required for USB interface support for a MFC application Pin
amit ghatwal12-Dec-07 18:57
amit ghatwal12-Dec-07 18:57 
GeneralRe: Help required for USB interface support for a MFC application Pin
Don Box12-Dec-07 19:31
Don Box12-Dec-07 19:31 
GeneralRe: Help required for USB interface support for a MFC application Pin
Cedric Moonen12-Dec-07 20:15
Cedric Moonen12-Dec-07 20:15 
QuestionHow to add SelectAll in CFileDialog Pin
santhoshv8412-Dec-07 17:42
santhoshv8412-Dec-07 17:42 
AnswerRe: How to add SelectAll in CFileDialog Pin
Naveen12-Dec-07 18:16
Naveen12-Dec-07 18:16 
GeneralRe: How to add SelectAll in CFileDialog Pin
santhoshv8412-Dec-07 18:36
santhoshv8412-Dec-07 18:36 
GeneralRe: How to add SelectAll in CFileDialog Pin
Naveen12-Dec-07 20:51
Naveen12-Dec-07 20:51 
QuestionRe: How to add SelectAll in CFileDialog Pin
David Crow13-Dec-07 4:29
David Crow13-Dec-07 4:29 
GeneralRe: How to add SelectAll in CFileDialog Pin
santhoshv8413-Dec-07 17:15
santhoshv8413-Dec-07 17:15 
GeneralRe: How to add SelectAll in CFileDialog Pin
David Crow14-Dec-07 2:55
David Crow14-Dec-07 2:55 
General"rich text file(RTF)" text extracting using CRichViewEdit Pin
CodingLover12-Dec-07 17:09
CodingLover12-Dec-07 17:09 
GeneralRe: "rich text file(RTF)" text extracting using CRichViewEdit Pin
CPallini12-Dec-07 21:37
mveCPallini12-Dec-07 21:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.