Aptitude (12) ASP.NET (2) Automata (4) Browser (1) C (5) C# (1) C++ (10) Code (3) CSS (1) Data Structure (1) DATABASE (3) HTML (1) java (43) JSP (1) math (1) MySql (8) other (6) php (3) Servlet (3)

Saturday, 9 March 2013

Binding

*Binding is an association of function calls to an objects.
*The normal bidind of member function call with an object is referred as compile time or static type or early binding
*c++ also supports runtime binding or dynamic binding or late binding


function binding:
binding  refers to the connection between a function call and the actual code executed as the result of the call.

in the process of an .exe file ,wherever the Linker encounters the  function call statement,it links it with that function difinition.which function definition to link the function call with ,is resolved by the compiler by mapping the logical addresses of the definitions at the compile-time itself.this process is called compile-time or static or early binding.

whenever the generic pointer is holding the address of the object of a derived class,and any function is invoked using that pointer,the compiler is unable to resolve this call at compile time .this is because the compiler can not invoke the appropriate function since the generic pointer will actually hold the address or will be type cast at run-time ()thats why it uses the static type of the pointer to govern the method invocation )

but in order to invoke the approprate function (i.e of the derived class),the compiler needs  to bind that funcion call to the correct function definition.The decision of which function to be invoked is taken at a later stage(i.e at run time).hence this feature is referred to as late (i.e run time)binding.This pointer is capable of pointing to an object at run time.hence it can invoke any function dynamically depending upon the type of the object that it is pointing to or the type of the object that it is type cast to.thats why it is also referred to as dynamic binding.
C++ supports this feature of dynamic biniding ny allowing us to typecast the generic pointer to the type of the object that it is pointing to.

No comments:

Post a Comment