Does destructor of a polymorphic base class that is protected need to be virtual?

If I have a base class for an inheritance tree, and the destructor is declared protected, do I still need to define this method as virtual? Why if I am not going to call it from this class? If I redefine it in a subclass, can I place it as public? Will base destructor be called automatically at end of subclass destructor?

1
2
3
4
5
6
7
struct GraphicObject
{
protected:
	/*virtual?*/ virtual ~GraphicObject() = default;
public:
	virtual void draw() = 0;
};


Regards
Is it ok to change the visibility of a method in a derived class?
the simple rule for base class destructors is "public and virtual or protected and non-virtual", see http://www.gotw.ca/publications/mill18.htm and https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-dtor-virtual

Is it ok to change the visibility of a method in a derived class?
of course, that's what using-declarations are for: https://en.cppreference.com/w/cpp/language/using_declaration#In_class_definition (this doesn't apply to destructors, though)

Last edited on
thanks!!
Topic archived. No new replies allowed.