lundi 27 mai 2019

Return a list of non const pointers by const reference to a list of const pointers

I'm facing this problem where one of my objects has a list of shared_ptrs to some object. so the type is like this list<shared_ptr<some_object>>. But the interface I'm implementing demands that this list be returned from a function with the following signature

const list<shared_ptr<const some_object>>& getObjList().

The compiler won't let me return my list since list<shared_ptr<const some_object>> and list<shared_ptr<some_object>> are not convertable to each other. Is there anyway I can return the required list without having to make a copy whose elements are shared_ptr<const some_object>?

Aucun commentaire:

Enregistrer un commentaire