binary '<<' : no operator defined

This is a discussion on binary '<<' : no operator defined within the C++ Programming forums, part of the General Programming Boards category; Ok, i'm new to c++ and im looking at classes and overloading. I keep getting this error in vis studio: ...

  1. #1
    Registered User gazsux's Avatar
    Join Date
    Mar 2002
    Posts
    72

    Angry binary '<<' : no operator defined

    Ok, i'm new to c++ and im looking at classes and overloading. I keep getting this error in vis studio:

    error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class CVector2' (or there is no acceptable conversion)

    all my main does is this at the mo:
    Code:
    int main()
    {
    CVector2 Vector1(0,1), Vector2(1,0), result;
    
    result = Vector1 + Vector2;
    
    cout << "Result: " << result << endl; /* line with error */
    
    return 0;
    }
    What does the error mean? and what am I doing wrong... if you need the class code, then just shout, ty

    Code tagged By Hammer

  2. #2
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    It mght be that you have not, in fact, defined an operator for inserting a CVector2 into an ostream.

    If this is the case, you will need to define it, in a function like this:

    Code:
    ostream& operator<< (ostream o, CVector2 cv) {
    
       o << '(' << cv.firstnumber << ", " << cv.secondnumber << ')';
    
       return o;
    
    }
    If you have a function along these lines somewhere in your program, you might need to check that it is being included and brought into scope.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trying to overload << in a templated Binary Tree
    By chinesepirate in forum C++ Programming
    Replies: 15
    Last Post: 11-23-2008, 03:07 PM
  2. Replies: 0
    Last Post: 11-04-2006, 11:07 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  4. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM

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