Results 1 to 6 of 6

Thread: early binding in a C++

  1. #1
    Join Date
    Nov 2009
    Posts
    51

    early binding in a C++

    I am studying in T.Y.B.Sc and attending course for C++ from NIIT. In c++ there is concept called early binding which is very tough. I unable to attend lecture for this topic and now I can not understand that topic. I want to know process of early binding through code. Please give me code that based on early binding.

  2. #2
    Join Date
    Apr 2008
    Posts
    4,642

    Re: early binding in a C++

    Using early binding direct function calls can be resolved. In early binding compiler is directly is associate with the identifier name using machine address. All function have same machine address so when the compiler calls to a function, it replace the call with machine language instruction that tells CPU to jump to the address of the function.

    Code:
     void Print(int n)
        {
            std::cout << n;
        }
    
          int main()
         {
            Print (6); 
            return 0;
         }

  3. #3
    Join Date
    May 2008
    Posts
    4,570

    Re: early binding in a C++

    Code:
    #include <iostream>
    using namespace std;
    
          int Add(int m, int m)
          {
              return m+n ;
           }
    
           int Subtract(int m, int n)
          {
              return m - n;
          }
     
           int Multiply(int m, int n)
           {
               return m * n;
            }
    
               int main()
            {
                int m;
                cout << "Enter a number: ";
                cin >> m;
     
               int n;
               cout << "Enter another number: ";
               cin >> n;
     
              int nOperation;
          do
            {
               cout << "Enter an operation (0=add, 1=subtract, 2=multiply): ";
               cin >> nOperation;
            } while (nOperation < 0 || nOperation > 2);
    
              int nResult = 0;
             switch (nOperation)
           {
                 case 0: nResult = Add(m, n); break;
                 case 1: nResult = Subtract(m, n); break;
                 case 2: nResult = Multiply(m, n); break;
          }
     
             cout << "The answer is: " << nResult << endl;
     
              return 0;
    }
    This program help you to understand the concept of early binding.

  4. #4
    Join Date
    May 2008
    Posts
    4,345

    Re: early binding in a C++

    Advantage of early binding is as follows-
    1 Your code is run faster than late binding because it complied all things first.
    2 Debugging is more faster and compiler is able to spot syntax error.
    3 You have full access over a project so that you can type keyword and dot operator to get list of properties and methods.
    4 You have full access to the application object via the Object browser.

  5. #5
    Join Date
    May 2008
    Posts
    4,831

    Re: early binding in a C++

    The events that takes place during compile time are called early binding. This shows that all the information which is require to call function is available at compile time. The compiler decide that which method give response to the request. The accessing of member functions of a class using pointer is an example of early binding.

  6. #6
    Join Date
    Apr 2008
    Posts
    1,948

    Re: early binding in a C++

    Code:
    #include <iostream>
    using namespace std;
    
    class Base 
     {
        public:
      virtual int f() const { return 1; }
     };
    
    class Derived : public Base 
    {
       public:
      int f() const { return 2; }
    };
    
    int main()
     {
      Derived d;
      Base* m1 = &n;
      Base& m2 = n;
      Base m3;
     
      cout << "m1->f() = " << m1->f() << endl;
      cout << "m2.f() = " << m2.f() << endl;
      cout << "m3.f() = " << m3.f() << endl;
    
    }

Similar Threads

  1. Modern Warfare 2 key binding
    By Coty in forum Video Games
    Replies: 4
    Last Post: 26-03-2010, 04:18 PM
  2. How to break through ip plus mac binding?
    By Langward in forum Networking & Security
    Replies: 5
    Last Post: 24-03-2010, 02:12 AM
  3. How to use early binding in Visual Basic. NET
    By Radames in forum Software Development
    Replies: 5
    Last Post: 11-02-2010, 05:53 AM
  4. What is Data Binding?
    By Rum in forum Software Development
    Replies: 5
    Last Post: 29-01-2010, 12:15 PM
  5. Late Binding in C#
    By Katty in forum Software Development
    Replies: 5
    Last Post: 27-11-2009, 10:09 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,061,568.73838 seconds with 16 queries