   gcc and temporary references
  if i have a method like so:void someFn(Vector3& param){  // use param here in some fashion}and i have calling code:someFn(Vector3(0,0,0));GCC cracks a spaz and makes me re-write it asVector3 temp = Vector3(0,0,0);someFn(temp);is there a compiler option i can set to stop this? its very annoying, and the problem also occurs with default variables!i was thinking i could override someFn to:void someFn(Vector3 param)but this is just gonna cause code bloat, but then again, making temporary variables is code bloat :P   
  I haven't used gcc much, but try changing the function to accept a const Vector & and see if that works?   ;  Isn't that how it should actually work considering you are passing by reference and not by value ? I would think that referencing a temporary variable can eventually lead to a major run time bug. ;  Right, that's probably why gcc is complaining. For some reason, VC++ DOES allow you to pass a temporary object to a function accepting a reference. Go figure :)   ;  It is because the parameter is not a reference to const. Imagine what would happen if you had code like this:void foo( int & x )    {   x = 0;    }    ...    foo( 5 ); // uh oh, 5 is now 0?  Try changing it to "void someFn(Vector3 const & param)".;  From http://www.techiwarehouse.com/cms/articles.php?cat=18 should answer your question.Quote:.Binding a Reference to an RvalueRvalues and lvalues are a fundamental concept of C++ programming. In essence, an rvalue is an expression that cannot appear on the left-hand side of an assignment expression. By contrast, an lvalue refers to an object (in its wider sense), or a chunk of memory, to which you can write a value. References can be bound to both rvalues and lvalues. However, due to the language's restrictions regarding rvalues, you have to be aware of the restrictions on binding references to rvalues, too. Binding a reference to an rvalue is allowed as long as the reference is bound to a const type. The rationale behind this rule is straightforward: you can't change an rvalue, and only a reference to const ensures that the program doesn't modify an rvalue through its reference. In the following example, the function f() takes a reference to const int:  void f(const int & i);int main(){f(2); /* OK */}The program passes the rvalue 2 as an argument to f(). At runtime, C++ creates a temporary object of type int with the value 2 and binds it to the reference i. The temporary and its reference exist from the moment f() is invoked until it returns; they are destroyed immediatly afterwards. Note that had we declared the reference i without the const qualifier, the function f() could have modified its argument, thereby causing undefined behavior. For this reason, you may only bind references to const objects.  ;  okay cool :) makes sence   ;Quote:Original post by JohnBoltonIt is because the parameter is not a reference to const. Imagine what would happen if you had code like this:void foo( int & x )    {   x = 0;    }    ...    foo( 5 ); // uh oh, 5 is now 0?  Try changing it to "void someFn(Vector3 const & param)".Even if you make the function void foo(const int &x); and do foo(5) it will not compile because now you cannot use x as lvalue anymore. This is the error it gives on gcc(g++) 3.4.1 on a solaris box(the only compiler I have access to at the moment) test.cpp: In function `void foo(const int&)':test.cpp:21: error: assignment of read-only reference `x';  Well, of course not. You can't alter the value of (a reference to) a const variable. Wouldn't make much sense, would it? If you want to modify the parameter but not have the modifications visible outside the call, just pass the parameter by value, not by reference. (Or you could create a local copy of a variable passed by reference, but why bother when the compiler can do that automatically?)   ;int f(const int &x){   return x+1;  }int main(int argc, char *argv[]){    f(5);}Compiles on 3.4.2 (MinGW)   