I have a really simple method:
void SomeClass::GetListStuff(std::vector<Stuff const *> &listStuff) const
{ listStuff = m_listStuff; }
Where m_listStuff is a member of SomeClass and is of type
std::vector<Stuff *>
This code gives me an error saying
there's no match for 'operator='
in 'listStuff = ((const SomeClass*)this)->SomeClass::m_listStuff
It works fine if I take the const away from the ListStuff pointer. I can also call insert() on listStuff (without changing the const correctness) and it works. Could anyone explain why?
I think you should do this:
That is, use
std::vector<Stuff*>instead ofstd::vector<Stuff const*>because I suspect thatm_listStuffis declared to bestd::vector<Stuff*>. So the argument type should match that.I think a better approach would be this:
Or even better is to expose iterators:
Write the non-const version yourself.