I'm writing a modular software, and I'm heading some problem with interfaces and memory.
I've a Base classe with some heavy work with association and composition so I prefer to write it once in an interface. problem is to avoid any memory leak or problems only my base class should be able to see the fields. Nobody else than Base should modify mFields list or free the pointers it contains. The problemns is Field will be derived, and methods will be added and my program who will use the Derived method should directly get list of DerivedField
class Base {
protected:
unique_ptr<BaseField> & addField(unique_ptr<BaseField> f) ;
const unique_ptr<BaseField> & something() ;
const unique_ptr<BaseField> & something2() ;
const std::list<const unique_ptr<BaseField>> & getFields() ;
private:
std::list<const unique_ptr<BaseField>> mFields ;
}
class Derived {
public:
unique_ptr<DerivedField> & addField(params) ;
const unique_ptr<DerivedField> & something() ;
const unique_ptr<DerivedField> & something2() ;
const std::list<const unique_ptr<DerivedField>> & getFields() ;
protected:
}
So mny question is how to get const std::list> & in Derived::getFields() with Base::getFields() ?
Thank you for your time Quentin
Aucun commentaire:
Enregistrer un commentaire