CU> Can someone please explain the difference of the following :
CU> CStringArray strMyArray;
CU> OR
CU> CStringArray *pstrMyArray = new CStringArray;
Both have an object constructed and declare and initialize a variable
to refer to it.
The differences are:
- the place where the memory for the object is allocated: the second
declaration allocates the required amount of memory for the object in
a "dynamic memory area", the first one (assuming the declaration is in
a function/method body) on the stack.
- the lifetime of the object: the object constructed by the first
declaration lives until the variable goes out of scope (i.e. until the
end of the surrounding block); the object constructed by the second
declaration lives until it is explicitly destructed.
Thomas
---
þ MM 1.0 #0113 þ FIRE DEPARTMENT - You set 'em, we wet 'em!!
---------------
* Origin: McMeier & Son BBS (2:301/138)
|