TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: ADAM MAJER
from: THOMAS MAEDER
date: 1998-02-02 20:23:00
subject: Darn Templates

AM> Could anyone explain those darn templates to me? I just started to l
AM> them and I got confused right at the start. Could anyone tell me wha
AM> wrong with the following:
About everything. The author of the template you quote doesn't know  a
lot more about templates than you. If you want to store information in
a linked list, use the list template from the Standard C++ Library.
AM> template 
AM> class _EXPORT TLinkedList    (_EXPORT just expands to _export in a D
AM>                                 and huge otherwise
AM> {
AM>         private:
AM>         TLinkedList *prev;
AM>         TLinkedList *next;
AM>         T *Struct;
AM>     public:
AM>         TLinkedList(){prev=NULL;next=NULL;Struct = new T};
AM>         ~TLinkedList();
AM>         BOOL Add();
AM>         void Assign(T *s){hmemcpy(Struct,s,sizeof(T));};
AM>         T* GetStruct(){return Struct;};
AM>         TLinkedList *Next(){return next;};
AM>         TLinkedList *Prev(){return prev;};
AM> };
AM> Then when I try to use that class I get more errors:
AM> class Boo
AM> {
AM>         ....
AM>         TLinkedList *List;     <- invalid use of tamplate !?!?!
AM> };
Yes, the right way would be 
TLinkedList List;
if  you  want  to  put  ints into your list (and analogously for other
element types).
Use 
list myList;
instead. If your library doesn't contain the list  template,  you  can
download  it  from  the  Internet (look for STL, the Standard Template
Library).
Thomas
---
 þ MM 1.0 #0113 þ Weather forecast for tonight: It's going to be dark!
---------------
* Origin: McMeier & Son BBS (2:301/138)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.