Turn from: http://blog.csdn.net/feixiaoxing/article/details/6769663
We discussed the content of basically C language, and haven't really touched on C + + related knowledge. After this blog, we will touch on the content of the class more. Class has a lot of properties, today we are talking about constructors, destructors.
(1) If there is no constructor, destructor.
View Plain class Apple {public:void print () const {return;} };
Although this class doesn't make sense, we find that it still takes up a byte if we use sizeof to calculate the size. So what if there's an Apple variable? To make Apple's variables meaningful, we try to make a difference:
View Plain 66:apple A; 67:a.print (); 00401248 Lea Ecx,[ebp-4] 0040124B call @ILT +0 (Apple::p rint) (00401005) 68:return; 69: We see that the stack allocates four bytes of space to a, which is a byte below the EBP.
(2) When the destructor is invoked.
View Plain class Apple {public:apple () {printf ("Apple ()!\n");} ~apple () {printf ("~apple ()!\n");} void print () const {return;}