c++ - Virtual destructor of abstract class fix is fuzzy -
i have abstract class , errors when try delete instance of class.
class ccobjectbase { public: ccobjectbase(); virtual ~ccobjectbase(); virtual void createpainterpath() = 0; }; class ctriangle : public ccobjectbase { public: ctriangle(); ~ctriangle(); void createpainterpath(); }; ccobjectbase :: ~ccobjectbase(){}
i create object bellow:
std::vector<ccobjectbase *> m_objectbaselist; m_objectbaselist.push_back(new ctriangle()); //do stuff m_objectbaselist delete m_objectbaselist.at(index); m_objectbaselist.erase(m_objectbaselist.begin() + index);
i retrieve error @ ~ctriangle()
"undefined reference ccobjectbase :: ~ccobjectbase()". if delete virtual destructor ccobjectbase warning "deleting object of abstract class type ccobjectbase has non-virtual destructor cause undefined behavior" annoying fix cause more problems.
update: kind of stupid tried run qmake -> rebuild , nothing happen when restart app there no errors or warnings displayed. why works now? not know.
your method
virtual ~ccobjectbase();
is undefined. declared, didn't provide definition. c++11 can change declaration
virtual ~ccobjectbase() = default;
for empty definition.
Comments
Post a Comment