Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: C++ more ef...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 44639 of 48002
Post > Topic >>

Re: C++ more efficient than C?

by "christian.bau" <christian.bau@[EMAIL PROTECTED] > Apr 10, 2008 at 02:19 PM

On Apr 10, 10:07=A0am, Ian Collins <ian-n...@[EMAIL PROTECTED]
> wrote:

> No you completely missed the point, if you loose pass by reference, you
> make operator overloading inefficient or down right ugly.

Let met suggest the following rule: A function argument can be either
a value, a const ref, or a non const ref. Say

  int f (int x);
  int g (const int& x);
  int h (int& x);

You call it as:

  f (y);
  g (y);
  h (&y);

Now what about operator overloading: If you overload operator+, like a
+ b, then the expectation is that a and b are unmodified. On the other
hand, if you overload operator+=3D, like a +=3D b, you expect a to be
modified and b to be unchanged. So here is the rule: Parameters that
would not be modified if the arguments were say plain int must be
either plain value or const&. Parameters that would be modified if
they were plain ints (like the "a" in a +=3D b) must be non-const
references, and in this case the & operator (or ref keyword) is _not_
used.
 




 1 Posts in Topic:
Re: C++ more efficient than C?
"christian.bau"  2008-04-10 14:19:55 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Oct 12 14:20:07 CDT 2008.