Re: Declare class pointer with or without new

Originally Posted by
Speedo
That might be a nice sentiment if it had much basis in reality. Alas, it really doesn't - there have been (and still are) innumerable programs written by experts and professionals that leak memory.
Even C++ for all of its complexities and flaws gives you tools to make memory management less of a problem. Not taking advantage of them when you have the opportunity is simply foolish.
It has alot to do with reality. First off I know professionals make mistakes, but really not on such a basic level. I never said using stl containers is bad and should be avoided. I bet you won't find a professional that wouldn't know how to probably handle memory.

Originally Posted by
Speedo
Polymorphism works just fine without new. About the only time that new is actually required for it is when you need a container of polymorphic objects.
and I think polymorphic objects in a container is important and there more reasons new is required than for placing derived objects into a container. Consider a factory design pattern. Alot depends on what is occuring at runtime and loads the specific derived type based on requirements. It would be hard to replace new with a local scoped object. It is possible, but wouldn't look as clean.
0100 0111 0110 1111 0110 0100 0010 0000 0110 1001 0111 0011 0010 0000 0110 0110 0110 1111 0111 0010
0110 0101 0111 0110 0110 0101 0111 0010 0010 0001 0010 0001 0000 0000 0000 0000 0000 0000 0000 0000