lundi 28 mars 2022

can dynamic binding happen without using pointer and using regular object in c++

#include<iostream>
using namespace std;
class Base{
    public:
    virtual void fun(){
        cout<<"Base"<<endl;
    }
};
class Derived:public Base{
    public:
    virtual void fun(){
        cout<<"Derived"<<endl;
    }
};
int main(){
    Derived d1;

    d1.fun(); // which binding work here? static binding or dynamic binding
    return 0;
}

In the above code I just want to know which binding will work in d1.fun() and why that binding happens ?
Please answer clearly if you know

Aucun commentaire:

Enregistrer un commentaire