return-by-reference

PHP Returning References

Returning by reference is useful when you want to use a function to find to which variable a reference should be bound. Do not use return-by-reference to increase performance. The engine will automatically optimize this on its own. Only return references when you have a valid technical reason to do so. whats does the...

C++: returning by reference and copy constructors

References in C++ are baffling me. :) The basic idea is that I'm trying to return an object from a function. I'd like to do it without returning a pointer (because then I'd have to manually delete it), and without calling the copy-constructor, if possible (for efficiency, naturally added: and also because I wonder if I can't avoid writi...

Prefix/Postfix increment operators

I'm wanting to make sure I understand pass-by-value vs pass-by-reference properly. In particular, I'm looking at the prefix/postfix versions of the increment ++ operator for an object. Let's suppose we have the following class X: class X{ private: int i; public: X(){i=0;} X& operator ++ (){ ++i; return *this; } //prefix increment...

Returning references from a C++ methods

Dear friends, i'm concerned if i'm making a bad use of references in C++ In the following method GCC complains warning "reference to local variable ‘me’ returned" MatrizEsparsa& MatrizEsparsa::operator+(MatrizEsparsa& outra){ MatrizEsparsa me(outra.linhas(),outra.colunas()); return me; } But, with the following changes the warning...

Scheme pass-by-reference

How can I pass a variable by reference in scheme? An example of the functionality I want: (define foo (lambda (&x) (set! x 5))) (define y 2) (foo y) (display y) ;outputs: 5 Also, is there a way to return by reference? ...

Overloaded [] operator on template class in C++ with const / nonconst versions

Whew, that was a long title. Here's my problem. I've got a template class in C++ and I'm overloading the [] operator. I have both a const and a non-const version, with the non-const version returning by reference so that items in the class can be changed as so: myobject[1] = myvalue; This all works until I use a boolean as the templa...