Class and Object and Memory in C++ Programming
When a class is specified, memory space of all the member function is allocated but memory allocation is not done for the data member. When an object is created, memory allocation for its data members is done. The logic behind separate memory allocation for member functions is quite obvious. All instances of a particular class would be using the same member functions but they may be storing different data in their data members. Memory allocation for objects is illustrated in fig below
Class and Object and Memory in C++ Programming |
It can be observed that “n” objects of the same class are created and data members of those objects are stored in distinct memory location, whereas the member functions of object 1 to object n are stored in the same memory area. Therefore, each object has a separate copy of data members and the different objects share the member functions among them.
Post A Comment:
0 comments so far,add yours