PDA

View Full Version : static Object Vs Pointer


rajeshs
10th June 2008, 14:56
Hi All,

I have one doubt in C++. I have seen many places in C++ programs while creating object somewhere static object is used like

Consider A as Class,

A a;

Somewhere we are creating objects as pointers like

A *a = new A();

I am having this doubt in this 2 approaches where to use static object and where to use pointer object ?

Please clear my doubt?

JimDaniel
10th June 2008, 15:48
Somebody was wondering the same thing a few days ago...also, I'm not sure its quite correct to refer to objects created on the stack as "static." C++ has a "static" keyword that means something quite different.

http://www.qtcentre.org/forum/f-general-programming-9/t-how-to-declare-objects-a-bit-out-of-context-but-very-confusing-13962.html

wysota
10th June 2008, 17:09
I tend to use the term "full/complete object" (in contrast to pointers that later get assigned a heap based object) for describing stack based objects.

rajeshs
11th June 2008, 06:22
Thank you for ur reply. Still i need clear difference between the both.

wysota
11th June 2008, 08:41
The only difference is that they are created in different regions of computer memory and heap based objects are persistent in such a way that they don't get deleted automatically as they have no scope. There are no general rules when to use which.