No best answer available. Please pick the good answer available or submit your answer.
September 16, 2005 04:39:41
vvvv
RE: What do you mean by binding of data and...
Encapsulation is the concept to binding of data and functions.The data members are allowed to access by appropriate class functions or methods.Data members can't access from outside class.
Data binding is the process of binding the data objects used by the program/application with the actual physical memory. Data Binding is further classified into two sub-concepts - Early binding and late binding. Early binding is the process of binding the data objects and the physical memory at compile time. In this process the memory is allocated to the data objects when the application/program is loaded into the memory for execution. All declarations of standard objects (e.g. int x; char y; MyClass myCls; etc) use early binding. Late binding is the process of associating/allocating memory to the objects at run-time when these objects are dynamically created. At compile time minimal memory is bound to these objects. Typically these are pointers. For example int* x[25]; is a pointer to 25 integers. At compile time 4 bytes of memory is allocated for the pointer itself. When a malloc calloc or new operator is used to allocate memory for x[25] ( x new int[25];) that's wheen the actual memory is allocated to hold 25 integers. Until such time no binding is done.
Apologies. Looks like I did not read the question properly in my previous answer.
Binding data and functions: One of the OO features supported by C++ is Encapsulation. Encapsulation is to have data and methods that can manipulate the data combined together in a single capsule (Object or Class). So in theory each C++ class has some (hopefully private) data members and (hopefully) some public members that can manipulate the data. These methods can be used to manipulate the data when an instance of the class is created in an application. The way memory is allocated for a class instance is as follows.
1. Memory for method code - per class used in the application. All member methods of the class are loaded here. 2. Memory for data members - per instance of the class. This memory is associated with a specific instance of the class. Each instance has its own data area in the memory where the data is manipulated. When a member function is invoked using an object the member method (in addition to its standard parameter list) will also take an invisible pointer parameter of the object's class tipe (called this). When the member method acts on the data it is acting on the object pointed to by this pointer. The this pointer is pointing to the unique data area (memory) allocated specifically for the object being referenced.
This is how data and member functions are bound together in C++.