After reading this post Use-cases of pure virtual functions with body? I am under the impression that it is possible to avoid using a pure virtual function with a body however I can't figure out how to do it in this case:
I have an abstract base class that I'll call "parent" and a collection of derived class that I'll call "child1", "child2" etc. I also have another class that I'll call "list" that contains an array of parent pointers that can be set to point to instances of various collections of children. For example, the array field of an instance of a list may contain pointers to 2 child1's and 1 child2.
When deleting an instance of list I'd like to free the various instances of child1's and child2's thus I need a destructor for child1,child2 etc. Additionally this requires me to have a destructor for the abstract parent class.
Again, the link above has persuaded me that I can find a way to not do this, or possible, that my problem is poorly conceived because I have found myself needing to do this.
If stack overflow is the wrong stackexchange for this question please let me know and I'll move it.
Thanks for the help PS: here is some code:
#include <iostream>
#define arlen 10
class parent{
public:
virtual ~parent();
void somefunction();
};
parent::~parent(){}
class child1: public parent{
public:
~child1();
void somefunction();
};
child1::~child1(){}
class child2: public parent{
public:
~child2();
void somefunction();
};
child2::~child2(){}
class list{
public:
parent* ar[arlen];
~list(){
for (int n=0; n<arlen; n++) delete ar[n];
}
}
int main(){}