In .h file
ostream& operator <<(ostream &os,const object &);
In .cpp file
ostream& operator <<(ostream &os,const object &mono)
{
os << mono.coef<<" *X^"<<mono.degree;
return os;
}
Errors I am getting:
error C2143: syntax error : missing ';' before '&'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2061: syntax error : identifier 'ostream'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int error C2805: binary 'operator <<' has too few parameters
I've checked every IO overloading tutorial I can found yet I cannot fix this.
EDIT: adding std:: fixed every error except "> error C2805: binary 'operator <<' has too few parameters " I dont know what that means
EDIT2: declaring function as a friend solved this. thanks everyone!
ostreamandobjectboth need namespace qualification. The former would bestd::ostream(make sure you have#include <ostream>) and the latter depends on whereobjectis declared in your codebase. - cdhowieostreamis unknown, you probably missed includingfstreamoriostream. - Mats Petersson<ostream>but there is no reason to include them just to getstd::ostream. - cdhowie