qazmlp said:
My class in a header file, contains inline virtual destructor.
Is this Ok? Can it cause any problems?
class base
{
public:
base() { }
virtual ~base { std::cout<<"Inside virtual destructor\n"; }
// Other members
};
1. don't try to inline stuff that is not trivial - template I/O is never
trivial - it's a horrendous mess of
inlined template stuff with conditions loops, exceptions etc. that the
compiler is virtually certain
do decide is way too hard to inline.
2. Apart from that inlining virtual dtors is a good idea if they are
trivial -
Every derived class dtor whether explicit or implicit will call the base
class dtor - if this can be inlined then
this should result in saving a function call.
3. The only other problem for trivial dtors is if the base class is ever
instantiated - If it is it will need a vtable
which will need an outline dtor. If you add a pure virtual method (the
dtor can be pure even if defined)
then the compiler should realise that the class cannot be instantiated
and
hence it will never need a vtable and hence never need an outlined dtor.
4. your compiler might not be that smart.