| Line 12: | Line 12: | ||
: How is it faster to copy a reference to a QString than to copy a pointer to a QString::Data (which is the entire non-static contents of a QString)? Someone please explain. [[User:Argonel|Argonel]] 01:03, 11 August 2007 (CEST) | : How is it faster to copy a reference to a QString than to copy a pointer to a QString::Data (which is the entire non-static contents of a QString)? Someone please explain. [[User:Argonel|Argonel]] 01:03, 11 August 2007 (CEST) | ||
| + | |||
| + | :: A pointer is a basic type, so this rule does not apply. Think of a reference as nothing else but a pointer with different syntax. API wise passing a const QString& is probably much better than working with a pointer to QString::Data... --[[User:Dhaumann|Dhaumann]] 10:39, 11 August 2007 (CEST) | ||
It should be mentioned, that when using d-pointers, the copy constructor and assignment operator either have to be implemented correctly or they have to be forbidden. The implicit copy constructor and assignment operator copy just the value of the pointer. The pointer to the former Private data will get lost (memory leakage).
"Each object parameter that is not a basic type (int, float, bool, enum, or pointers) should be passed by reference-to-const. This is faster, because it is not required to do a copy of the object."