I'm kind of confused about how the reference works in the code below.
From what I understand, b is just an alias of d1. So what's the difference between delete &b
and delete d1
?
b is of type Base but still is an alias of type f, so what differentiates them?
#include <iostream>
using namespace std;
class Base
{
public:
Base(){
cout << "Base Constructor Called\n";
}
~Base(){
cout << "Base Destructor called\n";
}
};
class Derived1: public Base
{
public:
Derived1(){
cout << "Derived constructor called\n";
}
~Derived1(){
cout << "Derived destructor called\n";
}
};
int main()
{
Derived1 *d1 = new Derived1();
Base &b = *d1;
delete &b;
}