Hi, My code compiles and run, but i've been told that it is quite problematic. I don't understand where do i go wrong.
Also, isn't it suppose to be wrong to declare "char _arrName[2];" and to do the assignment "_arrName[2]= '\0';" ? Isn't is a "out of boundaries" bug?
#include <iostream>
using namespace std;
class Base {
protected:
char* _name;
public:
virtual ~Base() { cout << "Base dtor of " << _name << endl; };
};
class D1: public Base {
char _arrName[2];
public:
D1() {
_name= _arrName;
_arrName[0]= 'D';
_arrName[1]= '1';
_arrName[2]= '\0';
}
virtual ~D1() { cout << "D1 dtor" << endl; }
};
int main () {
Base* arr[2];
arr[0]= new D1();
delete arr[0];
}