I always doubt when I should refer, and when I should use a variable pass. For example, one of the APIs is called by JOBJECTs -
QLIST retrive_cinemas(QString& options) { return (staticobject::getcinemas(options)); }
or
QLIST retrive_cinemas(QString options) { return (staticobject::getcinemas(options)); }
It seems to me that your problem can be reduced to something like this:
You have a function / method f()and class X, and you want to know if / when Xto pass in f()by reference or not.
f()
X
You can define three options:
void f(X v) // #1 - pass by value void f(const X& cr) // #2 - pass by const reference (&) void f(X& r) // #3 - pass by reference (&)
If it’s Xcheap to copy (like a int, a double, etc.) and you don’t want to change it, then pass the value (# 1).
int
double
X (, a vector, a string, ..), yo , pass by const (# 2).
vector
string
X f(), .
, , QString , , . a int double ( COW " ", , - - Win32 InterlockedIncrement() ), const (.. const QString &, # 2), .(QString&, # 3), .
QString
InterlockedIncrement()
const
const QString &
QString&
Qt , , , implicit sharing :
implicit sharing
++ Qt . , , , , --.
, , . !
. QString .
Qt , . - ( , QString), , , , .
, , ( , QString , , , ( )), , , . , / , . , const.