Quote:Original post by Zahlman
references can be used as l-values, so for example you could do createVector(myTail, myHead).doSomething();.
You can do that with an rvalue too.
Quote:Original post by Zahlman
references can be used as l-values, so for example you could do createVector(myTail, myHead).doSomething();.
inline const cl_3dVector < tType > & createVector(const cl_3dPoint < tType > & tail, const cl_3dPoint < tType > & head)
Quote:Original post by kelaklub
Then would you mind explaining where the unhappiness might arise from?
Quote:Original post by Skeleton_V@T
You might want to specify const-reference return value. This will ensure no temporary object will be created for efficiency and also protect your member variable from being undesirably mutated.
[Edit:]inline const cl_3dVector < tType > & createVector(const cl_3dPoint < tType > & tail, const cl_3dPoint < tType > & head)
Well, :-p you've already did it.
Quote:Original post by Zahlman
Well, that's not quite the whole story...
[18.15] Why does the compiler allow me to change an int after I've pointed at it with a const int*?
Causing a const int* to point to an int doesn't const-ify the int.The int can't be changed via the const int*, but if someone else has an int*(note: no const) that points to ("aliases") the same int, then that int* can be used to change the int. For example:
void f(const int* p1, int* p2) { int i = *p1; // Get the (original) value of *p1 *p2 = 7; // If p1 == p2, this will also change *p1 int j = *p1; // Get the (possibly new) value of *p1 if (i != j) { std::cout << "*p1 changed, but it didn't change via pointer p1!\n"; assert(p1 == p2); // This is the only way *p1 could be different } } int main() { int x = 5; f(&x, &x); // This is perfectly legal (and even moral!) ... }