ostream& operator<<(ostream& os, const vector<Point>& vec){
for (Point p : vec){
os << p << endl;
}
return os;
}
Very interesting but i actually did succeed with writing this vector<Point> into my .txt file but than i tryed to make operator<< work also just for a single Point just for completeness...
1 2 3 4 5 6
ofstream& operator<<(ofstream& ofs, const vector<Point>& vec){
for (Point p : vec){
ofs << p << endl;
}
return ofs;
}
Compiler gave me this error and i dont really understand it
Error 1 error C2440: 'return' : cannot convert from 'std::basic_ostream<char,std::char_traits<char>>' to 'std::ofstream &'
2
IntelliSense: a reference of type "std::ofstream &" (not const-qualified) cannot be initialized with a value of type "std::basic_ostream<char, std::char_traits<char>>"
I tested that i can use return ofs << p; but what if i wanted to add some chars somewhere around in case im writing this Point to file?
Ops! I didnt notice that everything is actualy working using ostream& operator<< :) So yea tnx for good tip :) It saves typing.
Ill leave this as unsolved just coz would be interesting to see why it didnt work not coz i would really need to use this overloading
Operator << returns ostream& reference for all builtin types.
You are not supposed to require derived types unless you need to use some of additional functionality. This is the point of inheritance and dynamic dispatch.
Thanks for answers guys :) I checked this version of code out and now its actually working so thats good to know. Now i can safety mark this as solved. Thank you guys a lot !!!