c++ - Am I required to overload my insertion operator here? -


am automatically required overload insertion operator when trying cout object?

here simple client file using practice overloading assignment:

int main() {   const fraction fr[] = {fraction(1,2), fraction(3,4), fraction(5,6)};     (int = 0; < 2; i++) {     cout << "fraction [" << <<"] = " << fr[i] << endl;   }    system("pause"); } 

and here relevant portion of header file works in place of cout:

void fraction::print() const {   cout << numer << " numerator " << denom << " denominator" << endl; } 

so when delete cout line , replace call print function works fine , prints out each corresponding parameter's value each fraction have in array. if try use cout freaks out , gives me compiler error. because need overload insertion operator?

if can explain error using terminology rather learn through method instead of random working bit of code. need learn material here if guys can explain in words deal is, awesome.

yes need overload << operator. there documentation here: http://en.cppreference.com/w/cpp/language/operators


Comments

Popular posts from this blog

rdbms - what exactly the undo information lives in oracle? -

bash - How do you programmatically add a bats test? -

java - Getting exception in JDBC thin driver -