//a simple class for binary number #include class BIN{ long data; friend ostream operator<< (ostream&, const BIN&); public: BIN(){data=0;}; BIN(long); BIN(BIN& x) // copy constructor { cout << "(copy)"; // data = x.data; } }; BIN::BIN(long x) { data=x; } int main() { long m; BIN y; m=126; y=m; cout << "m=" << m; cout << "=== y =" << y; cout << endl;; BIN x=y; // will call copy constructor cout << "\t x= " << x; cout << endl; cout << "What if the copy constructor is removed?\n\n"; while(m){ cout << "Input an integer:"; cin >> m; cout << "===" << (BIN)m; cout << " = " << m << endl; } cout << "Thank you for using AT&T:-)\n"; } ostream operator<< (ostream& oo, const BIN& x) { long tmp,i; tmp = x.data; for(i=1; i<=32; i++){ if(tmp<0) oo << 1; else oo << 0; if(i%4 == 0) oo << " "; tmp = tmp << 1; } return (ostream)oo; }