Re: CList Concept
- From: voidcoder <voidcoder@xxxxxxxxx>
- Date: Sun, 18 Mar 2007 12:50:42 +0100
>> CObject myObject = new CObject();
I have serious doubts the following is compiling
at all. Is it?
I believe you don't need to worry about the list element
destruction in case with CList<CObject,CObject&> myList.
A new instance of object (a copy) is created every time
you insert a new object to the list, and is destroyed
when you remove it from the list. But you have to cope with
releasing the source object. If you use "new", then it
should be a corresponding "delete" somewhere. Or better
allocate instance on the stack, so that it is destroyed
automatically:
CList<CObject,CObject&> myList;
CObject myObject;
myList.AddHead(myObject);
Normally collection templates are used to handle your
own classes, but if you want CObjects, just use CObjList
then.
Alternatively, if you want a list of pointers to
object instances (not a list of object instances),
use CPtrList then. In this case you are responsible
to create and release objects added to the list.
Jimmy Lim wrote:
Hi All,.
I have been using C for quite a long time so the object oriented concept is still a bit alien to me. There fore I just want to clarify the concept of the usage of CList.
Below is an example code:
//******************
CList<CObject,CObject&> myList;
CObject myObject = new CObject();
myList.AddHead(myObject);
CObject myObject2 = myList.RemoveHead();
//******************
Questions:
1. do I need to delete myObject after I have added it to myList?
2. if I do it this way, will I get memory leak?
What is the correct usage of CList, because I fear my way of implementation might cause memory leak. I'm coding in a WinCE environment.
Please advice. Thanks
- Follow-Ups:
- Re: CList Concept
- From: Jimmy Lim
- Re: CList Concept
- Prev by Date: Re: Stack used by thread
- Next by Date: Re: PXA270 and WinCE source code exemple ?
- Previous by thread: PXA270 and WinCE source code exemple ?
- Next by thread: Re: CList Concept
- Index(es):
Relevant Pages
|