Skip to main content
GameDev.net gamedev.net
🔒 Locked

strange STL error...

Started by null_pointer Jul 2, 2000 at 11:20 AM 2 replies 200+ views
Original Post
null_pointer
null_pointer
I''ve written a map editor, and separated it into 3 classes: image, font (which uses image), and map (which uses image). I''ve also written STL stream operators for my classes, so that I can stream them to and from disk. However, I am getting this really odd error:
quote:
MSVC error message c:\program files\microsoft visual studio\myprojects\battle force\editor\source\operators.cpp(86) : error C2679: binary ''<<'' : no operator defined which takes a right-hand operand of type ''class std::map,class std::allocator >'' (or there is no acceptable conversion)
Irritating, no? Here is the operator in which the error occurs: std::ostream& operator<<(std::ostream& os, map& map) { os << map.map_size.cx << map.map_size.cy; os << map.tile_size.cx << map.tile_size.cy; os << map.images; os << map.tiles; os << map.objects; return( os ); } Here are my operators: std::ostream& operator<<(std::ostream& os, map& map); std::istream& operator>>(std::istream& is, map& map); std::ostream& operator<<(std::ostream& os, map::script& script); std::istream& operator>>(std::istream& is, map::script& script); std::ostream& operator<<(std::ostream& os, map::tile& tile); std::istream& operator>>(std::istream& is, map::tile& tile); std::ostream& operator<<(std::ostream& os, map::object& object); std::istream& operator>>(std::istream& is, map::object& object); std::ostream& operator<<(std::istream& os, std::map& images); std::istream& operator>>(std::istream& is, std::map& images); std::ostream& operator<<(std::ostream& os, std::vector& tiles); std::istream& operator>>(std::istream& is, std::vector& tiles); std::ostream& operator<<(std::ostream& os, std::vector& objects); std::istream& operator>>(std::istream& is, std::vector& objects); I have implementations for all of those (I''ve checked and double-checked). If I move those operators to the global namespace, I get 2 errors (the same one, plus the istream version of it). How come?
- null_pointer Sabre Multimedia
deadlinegrunt
deadlinegrunt
Declare your stream members friends in your class

YAP YFIO,
deadlinegrunt
~deadlinegrunt
Kylotan
Kylotan
here:

std::ostream& operator<<(std::istream& os, std::map& images);
std::istream& operator>>(std::istream& is, std::map& images);

Spot the error in the top line:
ostream, not istream, surely?
null_pointer
null_pointer
That''s odd -- I copied and pasted this source from the map module (I''m dividing it into separate files)...somewhere I must have re-typed it, but I don''t remember doing that...

Thanks for you help!




- null_pointer
Sabre Multimedia

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.