Hi folks i only have one question.Can or should i delete a base class object instantiated in a derived class's constructor , inside the derived class's destructor?
class A {
protected:
int somedata;
public:
A () {}
A (int x) : somedata(x) {}
virtual ~A () {}
};
class B : public virtual A {
A* y;
public:
B () {}
B (int x) : A(x), y(new A()) {}
~B () {
delete y; //i get an exception and if i throw an std::exception() i get 'no named exception'
//doing this do i call the destructor of A twice?And if so .. how do i free the memory of y without calling delete on it?
}
};
Declaring A's destructor non virtual seems to work but what about the heap allocated memory?What am i missing?Thanks for the time