   Templating... why doesn't this work??
  Hi all,I''m never written my own templated class before.  I''ve always just made do with dynamic casts, etc.  But I thought I''d give it a go, only it''s just not going.I''m trying to make my own list class, a dynamically allocated array (I know others exist-- I am doing this for other reasons to integrate it with my own objects, and just to enjoy doing it)...So, I have gotten this far:List.h----------------------------------------------------#pragma oncetemplate class List{public:_T*mData;public:List<_T>(void);virtual ~List<_T>(void);public://///////////////////////////////////////////////////// Determines how many items are in the List//intmCount;inline intCount() {return mCount;}inline intGetCount() {return Count();}inline operator int(){return Count();}/////////////////////////////////////////////////////};---------------------------------------------------------List.cpp---------------------------------------------------------#include "list.h"templateList<_T>::List<_T>(void){mCount=0;}template List<_T>::~List<_T>(void){}------------------------------------------------------------Really simple stuff.  That''s just the preliminary.  So, I compiled it just to make sure it was okay, and it was.Then I instantiated a List, like so:List myList;Well, this makes the compiler croak, like so:TestBed error LNK2019: unresolved external symbol "public: __thiscall List::List(void)" (??0?$List@H@@QAE@XZ) referenced in function "public: virtual void __thiscall TestBedApp::Initialize(struct HINSTANCE__ *)" (?Initialize@TestBedApp@@UAEXPAUHINSTANCE__@@@Z)It throws the same problem for the destructor.  Can anyone tell me why it is that the constructor there is an unresolved symbol?  I would greatly appreciate it!Thanks!? 
  Okay, that instantiating...It''s actually List< int > myList...  (no spaces in the list type)It tossed out the  I guess it thought it was a tag. ;  template implementation cannot be in a separate (.cpp) file. You must put both declaration and implementation in one file. ;  Holy cow, really?  Why''s that?  Is there a way around it? ;quote:Original post by Goodlife  Holy cow, really?  Why''s that?  Is there a way around it?   If your compiler supports the export keyword (I think there''s only one that does). ;  the easy fix is to just put #include "List.cpp" at the bottom of your list.h   --{You fight like a dairy farmer!} ;quote:Original post by Goodlife  Holy cow, really?  Why''s that?When you get right down to it, the real reason is because it''s extremely difficult to write a compiler where separate compilation is possible. For more details see these articles: "Export" Restrictions, Part 1 and "Export" Restrictions, Part 2.quote:Is there a way around it?The only (easily available, relatively inexpensive, non-special purpose) compiler that I know of that supports export is Comeau''s compiler. ;  if all your functions are small, make them inline, and just put the function definitions in a .inl, and include that file at the bottom of List.h.  It helps to organize your code, and the compiler (at least vc++ 6) won''t go nuts. That''s what I do anyway.  Hope that helps, good luck!   ------------------------------I never chew my cabbage twice ;  Okay, I''ve just gone ahead and made everything inline.  They''re small, so it works nice.BUT... BUT!!!!!The templated version of my class breaks Visual Studio''s intellisense.  Anyone experience that before?  It breaks it everywhere under the class declaration, like://// Intellisense works here...//List<object> myList;//// Intellisense does not work here!//Any advice?? ;  If you separate the declaration and the definition, as you did first, you must define a List class for each type you use. Remember: List<A> and List<B> are two different classes, so each one must defined. Insert this in one  (not more!) of your .cpp files: template class List<int>;Then you will be able to use it.Reference: The C++ Programming Language, Bjarne Stroustrup [edited by - Poizon on February 16, 2004 12:57:45 PM]