If you initialize all objects in their constructors , those objects which got initialized, destructor will get called as well.
ithelp
Nearly a Posting Maven
2,230 posts since May 2006
Reputation Points: 769
Solved Threads: 128
Why should a constructor fail?
When you declare a constructor, all the instances of the class will have to use it, or variations of it (if you declare some).
unbeatable0
Junior Poster in Training
90 posts since Sep 2008
Reputation Points: 42
Solved Threads: 13
... when we called constructor , it allocate memory for the object . right .
A constructor does not allocate memory for the object. It does not know how to do that. Think about:
class C { public: C(); C operator+(const C&); }
...
C c; // static storage
void f() {
C c; // automatic storage
...
C* pc = new C(); // dynamic storage
... *pc + C ... // unspecified temporary storage
It's the same C::C() called!
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348