I'm creating my first class, mainly guided by Overland's C++ Without Fear. I've made the overloaded friend ostream operator<<, which works fine. I've also overloaded the * operator, and that works fine. What doesn't work is when I try to output the result of the * operator directly:
BCD bcd(10); //bcd is initialised to 10
BCD bcd2(15); //bcd2 is initialised to 15
cout << bcd; //prints 10
bcd2 = bcd2 * 2; //multiplies bcd2 by 2
cout << bcd2; //prints 30
cout << bcd * 2 //SHOULD print 20, but compiler says
//main.cpp:49: error: no match for 'operator<<' in 'std::cout << BCD::operator*(int)(2)'
For info, here are my prototypes:
BCD operator*(int z);
friend ostream &operator<<(ostream &os, BCD &bcd);
As far as I can tell, operator* returns a BCD, so operator<< should be able to print it. Help please!