R
Raider
I have library with some class having no virtual functions and non
virtual destructor.
I want to add new member functions to this class by creating derived
class and then use derived class instances as a base class instances:
// -------- library --------
class B
{
...
}
void f(B *b)
{
...
delete b; // calls B::~B() !
}
// ------- my code --------
class D : public B
{
public:
D(...) {}
void mf(); // I have access to B's protected members!
// no new member variables!!!
}
void h()
{
D* pd = new D(...);
d.mf();
f( pd );
}
I think it is ugly but safe. What do you think?
virtual destructor.
I want to add new member functions to this class by creating derived
class and then use derived class instances as a base class instances:
// -------- library --------
class B
{
...
}
void f(B *b)
{
...
delete b; // calls B::~B() !
}
// ------- my code --------
class D : public B
{
public:
D(...) {}
void mf(); // I have access to B's protected members!
// no new member variables!!!
}
void h()
{
D* pd = new D(...);
d.mf();
f( pd );
}
I think it is ugly but safe. What do you think?