what do you mean by "QList will allocate memory on the heap internally." ?
I mean if I do :
Number n(2);
list.append(n);
return list;
n will be deleted right ?
otherwise who will delete it
what do you mean by "QList will allocate memory on the heap internally." ?
I mean if I do :
Number n(2);
list.append(n);
return list;
n will be deleted right ?
otherwise who will delete it
n will be deleted but its copy that is in the list will get copied again and returned as part of the list. That's why you need to implement the copy constructor for your class. And if you make Number an implicitly shared class, only the facade part of the object will be allocated on the stack and the real data will reside on heap and will not be copied whenever the object itself is copied.
how do I make a class to be implicitly shared class ?
thanx
Open Qt Assistant and type in "Implicitly Shared Classes" in the index tab. Then type in "QSharedDataPointer".
Bookmarks