will i need virtual destructor when iam using boost::ublas matrix ? btw my class is really a template class

Would you mean you've this?

template <typename Whatever>
struct my_class
{
    // ...

    boost::ublas::matrix m;
};

There is nothing here that dictates you've got a virtual destructor.


You'll need a virtual destructor whenever you anticipate getting customers publically be a consequence of your class. To ensure that question ought to be "Customers will publically be a consequence of my class, will i require a virtual destructor?". Yes, you need to do.

This is because doing this can lead to undefined behavior:

struct base {}; // no virtual destructor
struct derived : base {};

base* b = new derived;

// undefined behavior, dynamic type does not match static type,
// and the base class does not have a virtual destructor
delete b; 

This doesn't:

struct base { virtual ~base(){} }; // virtual destructor
struct derived : base {};

base* b = new derived;

// well-defined behavior, dynamic type does not match static type,
// but the base class has a virtual destructor
delete b; 

Observe that it's nothing related to what people you will find within the base class. You always require a virtual destructor if customers is going to be removing derived classes via a pointer to some base class.


I would suggest you get a book so guess what happens it will, since it seems like you simply throw things around and hope it really works, which is not an excellent approach.