home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!microsoft!hexnut!jimad
- From: jimad@microsoft.com (Jim Adcock)
- Subject: Re: Do temps hurt performance of overloaded +
- Message-ID: <1992Dec17.210357.8792@microsoft.com>
- Date: 17 Dec 92 21:03:57 GMT
- Organization: Microsoft Corporation
- References: <1gofq7INN8q@golden.kaleida.com>
- Lines: 22
-
- In article <1gofq7INN8q@golden.kaleida.com> gordie@duts.ccc.amdahl.com writes:
- |If I do the following to overload binary + for a class, will temporary
- |objects be created? And if so, what can I do to prevent this, to get the best
- |performance?
- ....
- |inline Complex operator + (Complex& x, Complex& y)
- |{
- | return Complex (x.real + y.real, x.imaginary + y.imaginary);
- |}
-
- This of course is all very implementation dependent, but your approach
- works well with my compiler, not only avoiding temporaries, but
- actually resulting in compile-time evaluation of your
- expressions involving stack variables.
-
- In general where you pass-by-reference you should be passing by
- const ref:
-
- inline Complex operator + (const Complex& x, const Complex& y)
-
- to indicate the procedure does not modify those referenced.
-
-