Mail Archives: djgpp/1998/02/09/04:45:36
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 -