Results 1 to 4 of 4

Thread: c++

  1. #1
    Junior Member
    Join Date
    Feb 2007
    Answers
    7

    c++

    what is static or early binding and dynamic or late binding?


  2. #2
    Junior Member
    Join Date
    Jul 2007
    Answers
    1

    Re: c++

    Quote Originally Posted by sundarkms View Post
    what is static or early binding and dynamic or late binding?
    hello to all greek members


  3. #3
    Contributing Member
    Join Date
    Sep 2006
    Answers
    962

    Re: c++

    Static (or early) binding is the concept of resolving a function/method call at compile time. Function/subroutine calls are bound to specific computer memory locations where functions/subroutines are placed at compile time.

    Dynamic (or late) binding is the concept of resolving a method call at run time. The information available to the compiler at compile time, is the name of an operation, and a branch of the class hierarchy where this operation is defined:

    myVehicle -> stop;

    At run-time, the correct version of the stop method is selected, i.e. the version which corresponds to the class of the object which the variable myVehicle currently refers to, e.g. stop for Cars, stop for Plane etc


  4. #4
    Contributing Member
    Join Date
    Sep 2006
    Answers
    962

    Re: c++

    A code example of Static vs. Dynamic Bindning

    Static Binding
    The code segment below checks the type of the current Vehicle and calls the corresponding function:

    switch (myVehicle->type) {
    case CAR:
    x = stopCar();
    break;
    case PLANE:
    x = stopPlane();
    break;
    case BIKE:
    x = stopBike();
    break;
    default:
    error("Invalid");
    }
    This is difficult and error-prone to maintain, when new types of vehicles are added...


    Dynamic Binding
    The switch-statement above can be replaced by sending a message to the object which the variable myVehicle currently refers to:

    x = myVehicle->stop();

    In C++, the variable myVehicle would have been declared to be of type "reference to an instance of class Vehicle, or one of its subclasses":

    Vehicle* myVehicle;


    If you want more detailed example then visit the following page..

    http://msmvps.com/blogs/rakeshrajan/.../01/45188.aspx


    -----------------------
    suresh


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact