Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

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

  • 28-11-2011 07:04PM
    #1
    Registered Users, Registered Users 2 Posts: 429 ✭✭


    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, Registered Users 2 Posts: 2,065 ✭✭✭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, Registered Users 2 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
Advertisement