Click here to Skip to main content
15,847,902 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralRe: Basic doubt with Class template Pin
Richard MacCutchan6-Jul-11 22:59
mveRichard MacCutchan6-Jul-11 22:59 
GeneralRe: Basic doubt with Class template Pin
hrishi3217-Jul-11 1:08
hrishi3217-Jul-11 1:08 
GeneralRe: Basic doubt with Class template Pin
Richard MacCutchan7-Jul-11 2:33
mveRichard MacCutchan7-Jul-11 2:33 
GeneralRe: Basic doubt with Class template [modified] Pin
hrishi3217-Jul-11 17:28
hrishi3217-Jul-11 17:28 
GeneralRe: Basic doubt with Class template Pin
Richard MacCutchan7-Jul-11 23:54
mveRichard MacCutchan7-Jul-11 23:54 
GeneralRe: Basic doubt with Class template Pin
hrishi3218-Jul-11 0:18
hrishi3218-Jul-11 0:18 
GeneralRe: Basic doubt with Class template Pin
Richard MacCutchan8-Jul-11 1:31
mveRichard MacCutchan8-Jul-11 1:31 
AnswerRe: Basic doubt with Class template Pin
Orjan Westin5-Aug-11 9:49
professionalOrjan Westin5-Aug-11 9: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 17:09
mentorPaul M Watt10-Jul-11 17:09 
GeneralRe: Basic doubt with Class template Pin
hrishi32110-Jul-11 17:59
hrishi32110-Jul-11 17:59 
AnswerRe: Basic doubt with Class template Pin
Bram van Kampen19-Aug-11 15:54
Bram van Kampen19-Aug-11 15:54 
Questionbackgroud worker thread crashes but fine when foreground Pin
VeganFanatic26-Jun-11 5:44
VeganFanatic26-Jun-11 5:44 
AnswerRe: backgroud worker thread crashes but fine when foreground Pin
Richard MacCutchan26-Jun-11 6:18
mveRichard MacCutchan26-Jun-11 6:18 
GeneralRe: backgroud worker thread crashes but fine when foreground Pin
VeganFanatic26-Jun-11 6:19
VeganFanatic26-Jun-11 6:19 
GeneralRe: backgroud worker thread crashes but fine when foreground Pin
Richard MacCutchan26-Jun-11 6:44
mveRichard MacCutchan26-Jun-11 6:44 
GeneralRe: backgroud worker thread crashes but fine when foreground Pin
VeganFanatic26-Jun-11 6:46
VeganFanatic26-Jun-11 6:46 
GeneralRe: backgroud worker thread crashes but fine when foreground Pin
Richard MacCutchan26-Jun-11 6:57
mveRichard MacCutchan26-Jun-11 6:57 
GeneralRe: backgroud worker thread crashes but fine when foreground Pin
VeganFanatic26-Jun-11 6:58
VeganFanatic26-Jun-11 6:58 
GeneralRe: backgroud worker thread crashes but fine when foreground Pin
Richard MacCutchan26-Jun-11 7:06
mveRichard MacCutchan26-Jun-11 7:06 
GeneralRe: backgroud worker thread crashes but fine when foreground Pin
VeganFanatic26-Jun-11 7:08
VeganFanatic26-Jun-11 7:08 
AnswerRe: backgroud worker thread crashes but fine when foreground Pin
Albert Holguin5-Jul-11 10:52
professionalAlbert Holguin5-Jul-11 10:52 
AnswerRe: backgroud worker thread crashes but fine when foreground Pin
Paul M Watt10-Jul-11 17:24
mentorPaul M Watt10-Jul-11 17:24 
QuestionMigration from MFC to STL Pin
hrishi32122-Jun-11 21:28
hrishi32122-Jun-11 21:28 
AnswerRe: Migration from MFC to STL Pin
Alain Rist22-Jun-11 23:44
Alain Rist22-Jun-11 23:44 
GeneralRe: Migration from MFC to STL Pin
hrishi32126-Jun-11 19:28
hrishi32126-Jun-11 19: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.