I am using Qt to develop an applicatio for which I am seeing a segmentation fault in my destructor of my virtual base class on exiting the application. I think it's to do with declaring the member variable static, but I'm not certain. Any pointers on what's going on would help. Below is my sample code. I have removed all the member functions for clarity.
In header file:
class Base : public QObject
{
public:
Base() {}
virtual ~Base() = 0; /// Fault occurs here in the debugger
};
class Child1: public Base
{
public:
Child1() {}
~Child1() {}
};
class Service
{
public:
Service() {}
~Service() {}
private:
static Child1 m_base;
};
In source file:
Child1 Service::m_base;
When I exit the application I get a segmentation fault in the Base class destructor. Is it because m_base static member variable does not exist at the time the destructor is called, but it's virtual!
BTW, I got rid of the problem by making m_base a pointer to Base class and instantiating it in definition, but I'd still like to know what's wrong with the code above.
Thanks!