Overloading opreators error

Well, I am overloading the << and >> operators for two of my custom classes, and I am getting this error:

Error 4 error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>' c:\program files\microsoft visual studio 9.0\vc\include\istream 846


I can't figure out why it would be giving me that error...I've checked through the functions completely and they are all "correct." If someone really wants the code I could post it, but it's kind of long...for now I'll just post the prototypes:

1
2
3
4
fstream& operator << (fstream&, object&);
fstream& operator >> (fstream&, object&);
fstream& operator << (fstream&, player&);
fstream& operator >> (fstream&, player&);


Rather thanusing fstream, you should use istream for input and ostream for output.

Class object and player has to declare these functions as friends.

It's probably best if the output ones take const objects. e.g.
std::ostream& operator<<(std::ostream&, const player&);
Good point on the const obj thing, but when I use ostream/istream, it still gives me the same error...the only thing I can think of is that they aren't friends in my custom classes, although I am not accessing the variables directly (using member functions) so that shouldn't be a problem, right?
having trouble reproducing this error.
Couls you post some code?
Ok, I found the error. There was another function I was calling inside the the player loop that was expecting an istream, but since I was passing it an istream&, it was not liking it. Thanks for all the help guys =).
Last edited on
Topic archived. No new replies allowed.