"Having a container of pointers raises the question of how to destroy it. If you simply "do the right thing" and define a FilmList destructor that visits each of its pointers and deletes it, you must then worry about client code that contains a function with a FilmList value parameter. Recall that each value parameter causes a copy of the corresponding argument to be made. That copy is destroyed when the function returns. How should you deal with copying and destroying FilmList objects?"
- Intro to design patterns in c++ with qt 2nd edi.
if the function param did take a copy, and it would destroy the each copied object's pointer, how it should bother with original pointer? even I test it with a simpler replica of this design shown that the pointer in the original one is not deleted. Tested by printing out the current value of the pointer which shown it's address after each call to value-parametered function is called on it. The result is the same everytime which mean the pointer is not deleted / re-assigned. So what does the original question even mean?
simple replica:
class FractionList : public QList<Fraction*> {
public:
~FractionList() {
qDeleteAll(*this);
clear();
}
};
btw, I'm really bothered of the book author decision on inheriting every single time as possible. It's a good habit?