overloaded operators

This is a discussion on overloaded operators within the C++ Programming forums, part of the General Programming Boards category; Here is the function header const char* operator+=(const char []) What I am having trouble with is, I need to ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    12

    overloaded operators

    Here is the function header

    const char* operator+=(const char [])

    What I am having trouble with is, I need to return to array that this function receieves as an argument, so i need to return the part after the += sign, I have tried everything I could think of, any help would be great.

    Thanks

  2. #2
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    You shouldn't be returning the argument after the += operator; you should return the lefthand argument.

    a +=b;
    should return a after b is added to it.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  3. #3
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078

    Re: overloaded operators

    Originally posted by jccharl
    Here is the function header

    const char* operator+=(const char [])

    What I am having trouble with is, I need to return to array that this function receieves as an argument, so i need to return the part after the += sign, I have tried everything I could think of, any help would be great.

    Thanks
    You can't overload operators that work with just built-in types as you are attempting. You'd have to encapsulate at least one of those arrays in a class and then overload operators for that, otherwise it can't be done.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. iostream overloaded operators
    By peckitt99 in forum C++ Programming
    Replies: 1
    Last Post: 08-10-2007, 05:32 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  3. Problem with overloaded operators, templates and inheritance
    By bleakcabal in forum C++ Programming
    Replies: 1
    Last Post: 03-19-2004, 04:07 AM
  4. Polymorphism & Overloaded Operators :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 09-13-2002, 08:40 PM
  5. overloaded operators
    By ivandn in forum C++ Programming
    Replies: 2
    Last Post: 12-20-2001, 02:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21