Original Post
Hi, just a quick couple of questions: Firstly, if I want to return a shared_ptr to a thing I don't want modified, can I do it by returning a "const shared_ptr"? I know I can do it with normal pointers and references but will the reference counting stuff cock this up if I go copying it around and stuff? Secondly, why won't this work? I don't know a lot about much, so forgive me if it's blindingly obvious ;) I'm guessing that since the vector is templated on something non-const, it can't return it as const since that's a different type which can't be casted implicitly. What should I be writing instead if I want to return a vector of pointers to things I don't want changed? Cheers :)
class Something {
public:
std::vector<const boost::shared_ptr<SomeType>> getThings() {
return mThings;
}
private:
std::vector<boost::shared_ptr<SomeType>> mThings;
};