lvalue method

Benjamin Thaut code at benjamin-thaut.de
Fri Oct 8 00:33:22 PDT 2010


Hi, I'm writing a vec4 math struct and I have a method of which the 
return value has to be a lvalue so I wonder which is the correct way to 
do this:

vec4 Normalize() const { ... } //won't work, not a lvalue

ref vec4 Normalize() const {
   vec4 temp;
   ...
   return temp;
} //will this lead to a segfault or not?

ref vec4 Normalize() const {
   vec4* temp = new vec4;
   ...
   return *temp;
} //ugly, don't want to allocate anything on the heap

auto ref vec4 Normalize() const {
   vec4 temp;
   ...
   return temp;
} //will this lead to a segfault?

Or do I need to do it totaly in some other way?

-- 
Kind Regards
Benjamin Thaut


More information about the Digitalmars-d-learn mailing list