Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links



early binding in a C++

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 27-11-2009
Member
 
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.
Reply With Quote
  #2  
Old 27-11-2009
Eric B's Avatar
Member
 
Join Date: Apr 2008
Posts: 4,645
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;
     }
Reply With Quote
  #3  
Old 27-11-2009
Glenny's Avatar
Member
 
Join Date: May 2008
Posts: 4,550
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.
Reply With Quote
  #4  
Old 27-11-2009
JonathanD's Avatar
Member
 
Join Date: May 2008
Posts: 4,325
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.
Reply With Quote
  #5  
Old 27-11-2009
Macarenas's Avatar
Member
 
Join Date: May 2008
Posts: 4,810
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.
Reply With Quote
  #6  
Old 27-11-2009
Praetor's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,937
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;

}
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 12:15 PM.