Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Error: "no operator "<<" matches these operands

Options
  • 28-11-2011 7:04pm
    #1
    Registered Users Posts: 413 ✭✭


    I'm using C++ with allegro(don't think this has any affect on this issue) and Visual Studio 2010.

    Helpp pleeease. So annoying. See pic below.

    shapes.png


Comments

  • Registered Users Posts: 2,023 ✭✭✭Colonel Panic


    Did you overload operator << for the Shape class?
    std::ostream& operator<< (std::ostream &out, Shape &shape)
    {
       out << "This is a Shape! Yay!!!";
       return out;
    }
    

    You might need to make it a friend of Shape if you want to write out private members.


  • Registered Users Posts: 3,945 ✭✭✭Anima


    Yeah you need to overload the << operator or make a function and explicitly call it in your loop.

    Also with C++11 you can cut out some of the syntax for iterators by using the auto keyword.

    [PHP]
    for (auto it = s.begin(); it != s.end(); it++) {
    cout << *it << endl;
    }
    [/PHP]


Advertisement