Re: [C++]Class templates???

From: Rob Baumstark (shirak@CONNECT.AB.CA)
Date: 08/28/97


> From: Bode, Wyatt <wjbode@BEMIS.COM>
> To: CIRCLE@post.queensu.ca
> Subject:  [C++]Class templates???
> Date: Thursday, August 28, 1997 12:41 PM
>
> Anyone know how to properly use class templates in C++?  I bought a book
> on them this weekend, and was trying out one of the examples when MSVC
> 5.0 blew up.  I was modifying a linked-list class template, and this is
> what I get when I make the project:
>
> Linking...
> main.obj : error LNK2001: unresolved external symbol "public: __thiscall
> LinkedList<class CharString>::~LinkedList<class CharString>(void)"
> (??1?$LinkedList@VCharString@@@@QAE@XZ)
> main.obj : error LNK2001: unresolved external symbol "public: __thiscall
> LinkedList<class CharString>::LinkedList<class CharString>(void)"
> (??0?$LinkedList@VCharString@@@@QAE@XZ)
> Debug/Test.exe : fatal error LNK1120: 2 unresolved externals
>
> I get no compile errors, and this is my main function:
>
> #include "list.h"
>
> // a simple class to test the template...
> class CharString {
>         public:
>                 char text[256];
>
>                 inline CharString() { for (int i = 0; i < 256; i++)
> text[i] = '\0'; }
>                 inline CharString(const char *msg) { strcpy(text, msg);
> }
>                 inline ~CharString() { }
> };
>
> void main() {
>         LinkedList<CharString> test;
> }
>
>
> Any ideas?  I looked up templates in the MSVC manual, but everything I
> have looks right...  I would post the source code, but it's over 200
> lines and not everyone likes SPAM... 8-|
>
>         Thanks in advance,
>         Wyatt
----------
Well..., If you don't mind making the code MSVC++ only, I'd use one of the
built-in templates that comes with MSVC, in the STL (browse the CD for a
while).  Otherwise, I'd look through the code for them (also on the CD),
and the code for the MFC template based collections, try the CList class.
All of the MFC source should be on the CD too.
   Hope that helps.

-------------------------------------------------
     Rob Baumstark:   shirak@connect.ab.ca
                      cst0656@nait.ab.ca

   Forsaken Realms:   telnet://drewl.v-wave.com:4000
------------------------------------------------------


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/08/00 PST