user336635
user336635

Reputation: 2281

Do not want to copy on write

I've got class member:

QStringList list;  

How to avoid copying-on-write when returning this member and updating it?

Upvotes: 0

Views: 97

Answers (2)

Constantinius
Constantinius

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

paul23
paul23

Reputation: 9445

or you could get it by reference:

QStringList& LIST = myClass.list;

Upvotes: 1

Related Questions