Reputation: 2281
I've got class member:
QStringList list;
How to avoid copying-on-write when returning this member and updating it?
Upvotes: 0
Views: 97
Reputation: 35069
You could return a reference or a pointer to it:
QStringList& getList() {
return list;
}
This would return just a reference to your list. But essentially this would be the same as declaring list
public.
EDIT
This should work:
MyClass obj;
obj.getList().push_back("someStr");
Upvotes: 2
Reputation: 9445
or you could get it by reference:
QStringList& LIST = myClass.list;
Upvotes: 1