Describe static and dynamic binding of functions - C++

Describe static and dynamic binding of functions.

Static Binding :
By default, matching of function call with the correct function definition happens at compile time. This is called static binding or early binding or compile-time binding. Static binding is achieved using function overloading and operator overloading. Even though there are two or more functions with same name, compiler uniquely identifies each function depending on the parameters passed to those functions.

Dynamic Binding :
C++ provides facility to specify that the compiler should match function calls with the correct definition at the run time; this is called dynamic binding or late binding or run-time binding. Dynamic binding is achieved using virtual functions. Base class pointer points to derived class object. And a function is declared virtual in base class, then the matching function is identified at run-time using virtual table entry.
What are pure virtual functions?
What are pure virtual functions? - Pure virtual functions are also called ‘do nothing functions’...
What is a namespace? What happens when two namespaces having the same name?
What is a namespace? - A conceptual space for grouping identifiers, classes etc. for the purpose of avoiding conflicts....
What are the guidelines of using namespaces?
What are the guidelines of using namespaces? - To name a namespace, utilize the company name followed by the department and optionally followed by the features and technology used....
Post your comment
Discussion Board
expressing gratitude
thank u for ur explanation in the simple language the tough concepts.
at the edge time of exam I've been to ur explanation.
neeraj 04-17-2016
static bin
Static binding e.g occur at compile time... In c++ .

template
class Base
{
public:
Base(){};
void doOperation()
{
return static_cast(this)->doStaticOperation();
}

};

template
class MyClass : public Base
{
public:
doStaticOperation(){ cout << "We did it statically!" << endl; }
}
vicky 04-6-2016
static binding
Sir plz give me static dinding example
ravi bhatiya 03-4-2016
Dynamic Binding
using namespace std;
class A
{
public:
virtual void display()
{
cout<<"Base";
}
};

class B:public A
{
public:
void display()
{
cout<<"Derived";
}
};
int main()
{
B b;
A *a=&b;
a->display();
return 0;
}
Puneet Kumar Garg 01-22-2015