This page examines and gives a very clear example of how to dynamically load and use a class, there is something that I have a hard time understanding though:
I understand why is the "create" function needed, but why is a "destroy" function needed? why is not declaring the interface destructor as pure virtual enough?
I made an identical example with the exception of:
~polygon() = 0;
The destructor for triangle
is:
triangle::~triangle() {
std::cout << "triangle Dtor is called" <<std::endl;
}
then when I use:
delete poly;
the message is indeed shown (GCC 5.4.0 under linux).
I tried to look for other examples but they all mention and use the "destroy" function, there were no example using simply pure virtual destructors, which makes believe I'm missing something here, so .. what is it?
The background of not wanting to use a destroy function is that I want to use the allocated object in a shared_ptr
and not care later about its lifetime, working with a "destroy" function will be tricky, therefore I need to know if it's necessary.