(Be more explicit in the includes) |
|||
| (One intermediate revision by one user not shown) | |||
| Line 14: | Line 14: | ||
:: 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) | :: 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) | ||
| + | |||
| + | : We can't work with the QString::Data pointer at all, its private to the QString object, but it is the only data element inside a QString. So whether you pass a const QString& or a QString, you're passing the exact same sort of object. There is no speed increase, in fact I'd expect it to be slower because you have to dereference the const& every time you want to work with it. [[User:Argonel|Argonel]] 18:10, 11 August 2007 (CEST) | ||
| + | |||
| + | == Includes == | ||
| + | Can you please add that Qt includes should look like: | ||
| + | |||
| + | #include <QtCore/QObject> | ||
| + | |||
| + | And that includes from KDE should like like: | ||
| + | |||
| + | #include <KDE/KFile> | ||
| + | |||
| + | Rationale: it desambiguates the includes and makes it easier to port to other build systems. | ||
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."
Can you please add that Qt includes should look like:
And that includes from KDE should like like:
Rationale: it desambiguates the includes and makes it easier to port to other build systems.