| <<< Unary member operator syntax | Index | Available operators >>> |
// rational.h
#include <iostream>
using namespace std;
class Rational {
friend ostream& operator<<( ostream& os, Rational const& rat );
//...
};
// rational.cpp
ostream& operator<<( ostream& os, Rational const& rat )
{
os << "(" << rat.m_n << "/" << rat.m_d << ")";
return os;
}
// main.cpp
#include <iostream>
#include "rational.h"
using namespace std;
int main( )
{
Rational r1;
cout << r1 << endl;
return 0;
}
| <<< Unary member operator syntax | Index | Available operators >>> |