Thread: overloaded operators

  1. #1
    Registered User ivandn's Avatar
    Join Date
    Oct 2001
    Posts
    49

    overloaded operators

    Hi!

    Has anyone done much with overloaded operators.

    I've got a '<<' and a '+' which work fine but when I try to do,

    cout << a + b;

    it says no match for ostream& << MYCLASS

    '<<' is a friend and a+b accepts parameters by value ad returns by value (not reference)

    Has anyone seen anything like this before?

    Thanks
    Ivan

  2. #2
    Registered User ivandn's Avatar
    Join Date
    Oct 2001
    Posts
    49
    OK,

    FYI

    // this wouldn't work for cout << a + b;
    friend ostream& operator<< (ostream& out, MyClass &obj);

    // this works for cout << a + b;
    friend ostream& operator<< (ostream& out, MyClass obj);
    Ivan

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    421

    Talking

    When you overloaded your + operator what value are you returning??

    you're going to have to paste a bit of code before i can help you.. please paste your operator+ and operator<< routines.

    thanks
    U.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

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, 05:45 PM
  3. Problem with overloaded operators, templates and inheritance
    By bleakcabal in forum C++ Programming
    Replies: 1
    Last Post: 03-19-2004, 05:07 AM
  4. Polymorphism & Overloaded Operators :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 09-13-2002, 08:40 PM
  5. help with overloaded operators
    By doleman19 in forum C++ Programming
    Replies: 23
    Last Post: 10-23-2001, 02:40 AM