TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: ADAM MAJER
from: JAN BIJSTERBOSCH
date: 1998-02-03 19:38:00
subject: Darn Templates

Hello Adam,
31 Jan 98, Adam Majer of 1:348/203 wrote to All
 AM> Could anyone explain those darn templates to me? I just
 AM> started to learn them and I got confused right at the start.
 AM> Could anyone tell me what is wrong with the following:
 AM> template 
 AM> class _EXPORT TLinkedList    (_EXPORT just expands to
 AM> _export in a DLL
 AM>                                 and huge otherwise
Hmm, I'm not familiar with the _EXPORT directive but I would leave it out for 
the moment since I'm not shure templates can be incorporated in DLL's
 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:
What more errors? Where did the above give you any errors?
 AM> class Boo
 AM> {
 AM>         ....
 AM>         TLinkedList *List;     <- invalid use of tamplate
 AM> !?!?!
 AM> };
The above is an obvious mistake. You declared an instance of the template, 
but you didn't tell the compiler what type of variable the template must be 
for. You should have typed something like: TLinkedList *List;
 AM> Everything compiles right in the template but I get whole
 AM> bunch of errors and I try to use it (template). I wanted the
 AM> T (the  in the template class) to point to a structure
 AM> which is later called from another class.
Hmm, I'm not shure what you exactly mean by called from another class, but it 
would be no problem to make class Boo a template class too. e.g.:
template
class Boo {
        ....
        TLinkedList *List;
        ....
};
and somewhere in you program you could use:
Boo testcase;
 AM> Any kind of help will be very appreciated. Thanx in
 AM> advance...
I hope this brought some light to the subject. ;-))
Greetings from sunny Amsterdam,
       Jan
email:bijster@worldonline.nl
http://www.worldonline.nl/~bijster
--- MBM v3.41e
---------------
* Origin: Snuffelaar bij DosBoss West (2:500/121.5122)

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™.