www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/09/04:45:36

From: hat AT se-46 DOT wpa DOT wtb DOT tue DOT nl (Albert Theo Hofkamp)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: problem with list class
Date: 9 Feb 1998 09:15:27 GMT
Organization: Eindhoven University of Technology, The Netherlands
Lines: 41
Message-ID: <6bmhff$d0s@tuegate.tue.nl>
References: <34D1ADCD DOT 5CBB9988 AT sis DOT co DOT at>
<u6GuKIoL9GA DOT 365 AT upnetnews02 DOT moswest DOT msn DOT net>
<34DB0C12 DOT 923FFFC9 AT sis DOT co DOT at>
Reply-To: a DOT hofkamp AT wtb DOT tue DOT nl
NNTP-Posting-Host: se-46.wpa.wtb.tue.nl
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In article <34DB0C12 DOT 923FFFC9 AT sis DOT co DOT at>,
	Gruber Gerhard <g DOT gruber AT sis DOT co DOT at> writes:
> DeHackEd wrote:
> 
> This makes templates not as attractive as I thought first, because how
> will I access template functions within a class when I have to define
> the template funcitonality outside of it?

You should differentiate between the class which is an element of the
list, and the class containing the list itself.

For a list windows, you'd do:

class CWindow { ... };	// Define everything you want to do with a single
			// window here.

typedef list<CWindow> CWindowList;
			// CWindowList is a list of windows.
			// All methods of CWindowList are defined in
			// the template.

Note that appending a CWindow to the list makes a copy of that class using the
copy-constructor.
If that's not what you want, you can do

class CWindowList: public list<CWindow*> { ...  }

`list<CWindow*>' is a list of pointers to windows. However, deleting the list
will not delete the window objects, since pointers are not followed.
(maybe list<CWindow&> would, I have never tried that).

if you derive a class CWindowList from the list, you can define your own
destructor, and also define new methods (eg, counting the #windows which
are opened).



Albert
---
Sorry, no .sig
The sys admin wiped the previous sig, and I haven't invented a new one yet.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019