Click here to Skip to main content
15,899,126 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralRe: Basic doubt with Class template Pin
Richard MacCutchan6-Jul-11 21:59
mveRichard MacCutchan6-Jul-11 21:59 
GeneralRe: Basic doubt with Class template Pin
hrishi3217-Jul-11 0:08
hrishi3217-Jul-11 0:08 
GeneralRe: Basic doubt with Class template Pin
Richard MacCutchan7-Jul-11 1:33
mveRichard MacCutchan7-Jul-11 1:33 
GeneralRe: Basic doubt with Class template [modified] Pin
hrishi3217-Jul-11 16:28
hrishi3217-Jul-11 16:28 
GeneralRe: Basic doubt with Class template Pin
Richard MacCutchan7-Jul-11 22:54
mveRichard MacCutchan7-Jul-11 22:54 
GeneralRe: Basic doubt with Class template Pin
hrishi3217-Jul-11 23:18
hrishi3217-Jul-11 23:18 
GeneralRe: Basic doubt with Class template Pin
Richard MacCutchan8-Jul-11 0:31
mveRichard MacCutchan8-Jul-11 0:31 
AnswerRe: Basic doubt with Class template Pin
Orjan Westin5-Aug-11 8:49
professionalOrjan Westin5-Aug-11 8:49 
If you are still looking for an answer, I posted an article explaining this just today.
http://www.codeproject.com/Articles/236927/All-your-base64-are-different-to-us

In short, there is a way, provided you know all template types you will be using. I'll copy the example I had in the article here:

C++
-------------------------------------
-- In my_template.h file
...
template <typename T>
T my_temp_func(const T& t);

-------------------------------------
-- In my_template.cpp file

#include "my_template.h"

// Definition
template <typename T>
T my_temp_func(const T& t)
{
  return t;
}

// Instantiation declaration
int my_temp_func<int>(const int& t);

-------------------------------------
-- In using_my_template.cpp
#include "my_template.h"
...
int i = my_temp_func<int>(4); // works
string s = my_temp_func<string>("Abob"); // link error


In the example above, the declaration in the last line of my_template.cpp tells the compiler there’ll be a variant of the template function that uses int as template parameter. Okay, says the compiler, I’ll put an inline copy there. Since the generic definition is right there in the same compilation unit (ie my_template.cpp), this is something the compiler can do – it has all the information it needs.

The result of that is that in the compiled file (probably called my_template.obj) there is now a function that has the signature int my_temp_func(const int& t). This is a fully defined specialisation of a template function, so to the linker it looks just like a normal function.

However, the linker won’t be able to find a string specialisation, so this will generate a linker error.

In
AnswerRe: Basic doubt with Class template Pin
Paul M Watt10-Jul-11 16:09
mentorPaul M Watt10-Jul-11 16:09 
GeneralRe: Basic doubt with Class template Pin
hrishi32110-Jul-11 16:59
hrishi32110-Jul-11 16:59 
AnswerRe: Basic doubt with Class template Pin
Bram van Kampen19-Aug-11 14:54
Bram van Kampen19-Aug-11 14:54 
Questionbackgroud worker thread crashes but fine when foreground Pin
VeganFanatic26-Jun-11 4:44
VeganFanatic26-Jun-11 4:44 
AnswerRe: backgroud worker thread crashes but fine when foreground Pin
Richard MacCutchan26-Jun-11 5:18
mveRichard MacCutchan26-Jun-11 5:18 
GeneralRe: backgroud worker thread crashes but fine when foreground Pin
VeganFanatic26-Jun-11 5:19
VeganFanatic26-Jun-11 5:19 
GeneralRe: backgroud worker thread crashes but fine when foreground Pin
Richard MacCutchan26-Jun-11 5:44
mveRichard MacCutchan26-Jun-11 5:44 
GeneralRe: backgroud worker thread crashes but fine when foreground Pin
VeganFanatic26-Jun-11 5:46
VeganFanatic26-Jun-11 5:46 
GeneralRe: backgroud worker thread crashes but fine when foreground Pin
Richard MacCutchan26-Jun-11 5:57
mveRichard MacCutchan26-Jun-11 5:57 
GeneralRe: backgroud worker thread crashes but fine when foreground Pin
VeganFanatic26-Jun-11 5:58
VeganFanatic26-Jun-11 5:58 
GeneralRe: backgroud worker thread crashes but fine when foreground Pin
Richard MacCutchan26-Jun-11 6:06
mveRichard MacCutchan26-Jun-11 6:06 
GeneralRe: backgroud worker thread crashes but fine when foreground Pin
VeganFanatic26-Jun-11 6:08
VeganFanatic26-Jun-11 6:08 
AnswerRe: backgroud worker thread crashes but fine when foreground Pin
Albert Holguin5-Jul-11 9:52
professionalAlbert Holguin5-Jul-11 9:52 
AnswerRe: backgroud worker thread crashes but fine when foreground Pin
Paul M Watt10-Jul-11 16:24
mentorPaul M Watt10-Jul-11 16:24 
QuestionMigration from MFC to STL Pin
hrishi32122-Jun-11 20:28
hrishi32122-Jun-11 20:28 
AnswerRe: Migration from MFC to STL Pin
Alain Rist22-Jun-11 22:44
Alain Rist22-Jun-11 22:44 
GeneralRe: Migration from MFC to STL Pin
hrishi32126-Jun-11 18:28
hrishi32126-Jun-11 18:28 

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.