How it is determined whether the below call is bound at compile time or at runtime?
object.member_fn;//object is either base class or derived class object
p->member_fn;//p is either base class or derived class pointer
EDITED:
#include <iostream>
using namespace std;
class Base
{
public:
Base(){ cout<<"Constructor: Base"<<endl;}
~Base(){ cout<<"Destructor : Base"<<endl;}
};
class Derived: public Base
{
//Doing a lot of jobs by extending the functionality
public:
Derived(){ cout<<"Constructor: Derived"<<endl;}
~Derived(){ cout<<"Destructor : Derived"<<endl;}
};
void foo()
{
Base & Var = Derived();
Base*pVar = new Derived;
delete pVar;
}
void main()
{
foo();
std::cin.get();
}
out put:
Constructor: Base
Constructor: Derived
Constructor: Base
Constructor: Derived
Destructor : Base // the Derived is not called,
// the PVal is of type Base* and the fn is not virtual
//so compile time binding
Destructor : Derived
Destructor : Base