Hello,
I solved a problem that troubled me for a while and now I am interested in getting more insight into what has been happening here..
I have a custom data type that I want to store as a value in QMap.
QMap<uint, CustomType>
QMap<uint, CustomType>
To copy to clipboard, switch view to plain text mode
My CustomType looks like:
class CustomType
{
public:
CustomType() { m_objectRef = nullptr; m_slotName = nullptr; }
CustomType
(QObject* obj,
const char* slotName
) { m_objectRef
= obj; m_slotName
= slotName;
} virtual ~CustomType() {}
// Accessors
QObject* GetObjectName
() { return m_objectRef;
} const char* GetSlotName() { return m_slotName; }
private:
const char* m_slotName;
};
class CustomType
{
public:
CustomType() { m_objectRef = nullptr; m_slotName = nullptr; }
CustomType(QObject* obj, const char* slotName) { m_objectRef = obj; m_slotName = slotName; }
virtual ~CustomType() {}
// Accessors
QObject* GetObjectName() { return m_objectRef; }
const char* GetSlotName() { return m_slotName; }
private:
QObject* m_objectRef;
const char* m_slotName;
};
To copy to clipboard, switch view to plain text mode
I get a compilation error saying:
undefined reference to `_imp___ZTV10CustomType'
undefined reference to `_imp___ZTV10CustomType'
To copy to clipboard, switch view to plain text mode
Solution:
Remove virtual keyword from the destructor.
My question:
Why can't I have a virtual destructor here?
Thank you!
Regards
Vikram
Bookmarks