hat is the output of the given code? #include using namespace std; class Base { pub
What is the output of the given code?
#include<iostream>
using namespace std;
class Base {
public:
Base()
{ cout<<"Constructing Base \n"; }
virtual~Base()
{ cout<<"Destructing Base \n"; }
};
class Derived: public Base {
public:
Derived()
{ cout<<"Constructing Derived \n"; }
~Derived()
{ cout<<"Destructing Derived \n"; }
};
int main(void)
{
Derived *d = new Derived();
Base *b = d;
delete b;
return 0;
}
Code:
#include<iostream>
using namespace std;
class Base {
public:
Base()
{ cout<<"Constructing Base \n"; }
virtual~Base()
{ cout<<"Destructing Base \n"; }
};
class Derived: public Base {
public:
Derived()
{ cout<<"Constructing Derived \n"; }
~Derived()
{ cout<<"Destructing Derived \n"; }
};
int main(void)
{
Derived *d = new Derived();
Base *b = d;
delete b;
return 0;
}
Step by step
Solved in 2 steps with 1 images