Virtual destructors only in selected databases

This is a key element that is not covered by this (although it provides interesting information). My code is as follows:

struct concept { virtual ~concept() = default; }; struct policy { protected : ~policy() = default; }; struct implementation final : concept, policy { }; 

If I use this hierarchy only with pointers to concept :

 unique_ptr<concept> = make_unique<implementation>(); 

is safe above ?

I believe that if someone tried to delete using the pointer to the policy protected destructor would not allow it (a trick from Modern C++ design ), but does everything else work fine? (namely, when a concept pointer is deleted, are hierarchy destructors guaranteed to be called correctly?)

+7
c ++ c ++ 14
source share
1 answer

Since ~concept() is virtual, when you delete object using the concept pointer, it calls ~implementation() .

I see no reason why the rest will not work as they should.

+5
source share

All Articles