Thread: Quick Question +=

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    224

    Cool Quick Question +=

    Hey,

    I came across this +=

    Tried searching the i-net but nothing came up? So what does this do?

    From where I saw it my guess is:

    instead of x = x + y;
    you have x += y;

    Is this right?

    Are there any drawbacks etc. to using this? What are the advantages?

    Cheers

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    AFAIK ..no drawbacks..
    As for advantages...IS there anything other than "Cleaner code" ?

  3. #3
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    From where I saw it my guess is:

    instead of x = x + y;
    you have x += y;

    Is this right?
    Why on Earth would you:
    Open browser
    Type/click to visit here
    Login
    Click new post
    Type your post
    Click post
    Logout

    and not
    Create file/Open IDE
    Type a 6 line test program
    Compile
    Observe output

    You searched, which is laudable, but then you gave up! Wikipedia may frown on original research, but software develoment isn't wikipedia. Paraphrasing somebody in a different thread
    Just try things out. The world wont end if you try something and it doesn't work.
    Are there any drawbacks etc. to using this? What are the advantages?
    It's exactly the same as writing 5+5+5 as 5*3 except for objects where += can be overloaded seperately from +
    Last edited by adeyblue; 05-11-2011 at 01:04 PM.

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    When the types of x and y are a class or some kind, then the operator += is typically more efficient than using operator + because no temporary objects will be created.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    Registered User
    Join Date
    Nov 2006
    Posts
    224
    Thanks for the productive posts!!

    As for adeyblue... why even bother replying (SMH)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. quick question
    By mkeisu in forum C++ Programming
    Replies: 20
    Last Post: 05-14-2008, 09:21 AM
  2. A quick question
    By abh!shek in forum C++ Programming
    Replies: 22
    Last Post: 04-20-2008, 11:14 AM
  3. Quick question
    By mattio87 in forum C Programming
    Replies: 9
    Last Post: 05-04-2007, 05:19 AM
  4. Quick Question!
    By dizz in forum C++ Programming
    Replies: 14
    Last Post: 11-21-2002, 07:02 AM
  5. Quick question
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 04-05-2002, 12:11 PM