c++ - IO operator overloading error -


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 getting:

error c2143: syntax error : missing ';' before '&'
error c4430: missing type specifier - int assumed. note: c++ not support default-int
error c2061: syntax error : identifier 'ostream'
error c4430: missing type specifier - int assumed. note: c++ not support default-int error c2805: binary 'operator <<' has few parameters

i've checked every io overloading tutorial can found yet cannot fix this.

edit: adding std:: fixed every error except "> error c2805: binary 'operator <<' has few parameters " dont know means

edit2: declaring function friend solved this. everyone!

you using ostream without qualifying namespace std::

use

std::ostream& operator <<(std::ostream& os,const object& mono)


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -