Click here to Skip to main content
15,851,915 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
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 
AnswerRe: Basic doubt with Class template Pin
Paul M Watt10-Jul-11 17:09
mentorPaul M Watt10-Jul-11 17:09 
Templates behave a lot like inline functions. The entire implementation is required to be declared in the include file for the compiler to use it correctly.

I believe you have described this method in your question, but I would like to start here, because it is the method I prefer if I dont want a single .h file implementation. I will use the file name Tmp.x for all of the examples, where x is the extension.

1) You declare all of your template classes and functions in your file Tmp.h .

2) Then implement all of the functions in a separate file with an extension such as Tmp.inl (inline). It is important that when the function definitions appear outside of the class definition, that you declare each function declaration with inline. Otherwise if you include this header file in multiple places, you will get linker errors for duplicate symbols.

3) At the bottom of Tmp.h and the line #include "Tmp.inl". The file implemented in step 2.

If you prefer to have the file extension to still be .cpp, you can use that as well. You would follow all of the steps the same way, and include the .cpp file at the end of the .h file. The only difference, in your Visual Studio project, you will have to change the settings for the file so that it does not get compiled like the other .cpp files. It is already included in a header file.


You cannot get around having the Template implementation available to the compiler when it sees the first usage of the template.
Why? Because that is the point where the compiler generates the actual code from the template.

Originally there was supposed to be a keyword "export" to allow the templates to be defined like regular classes, but that never became part of the standard, and therefore is not available.

Hopefully this helps.
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 
GeneralRe: Migration from MFC to STL Pin
Alain Rist26-Jun-11 22:18
Alain Rist26-Jun-11 22:18 

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.