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
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

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

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


    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,062 ✭✭✭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