0

I have some problem inside my project: I have a class named Item that represents item inside a store, it has three attitudes like string of name and it's cost. in the main program I'm using set of items (set<Item>) and the problem is when I'm trying to print the set using the copy algorithm:

copy(items.begin(), items.end(), ostream_iterator<Item>(cout, " ## ")); the problem is that the compiler sends me this error:

Error 1 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const Item' (or there is no acceptable conversion)

I really don't know why its happen to me, help please ?

DR J
  • 73
  • 7
  • 3
    http://stackoverflow.com/questions/476272/how-to-properly-overload-the-operator-for-an-ostream – RyanP Jan 12 '17 at 17:28
  • Show a [mcve], please. In particular, do you actually have a suitable streaming operator defined for your class? – Angew is no longer proud of SO Jan 12 '17 at 17:28
  • 1
    Did you overload the `std::ostream& operator << (...)` for your `Item` class?.. The error you are seeing is even quite informative compared with what we saw with older compilers years ago. – WhiZTiM Jan 12 '17 at 17:29
  • should I ? @WhiZTiM – DR J Jan 12 '17 at 17:31
  • @DRJ, No, the compiler's AI will overload it for you:-).. Ok, quips aside. . . Yes, you should overload it, Read the [Operator Overloading](http://stackoverflow.com/questions/4421706/operator-overloading?rq=1) on Stackoverflow. Also you may want check out some really [good C++ resources](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) curated by the C++ community here. – WhiZTiM Jan 12 '17 at 17:39

0 Answers0