I am busy doing an assignment for a Comp Sci module in C++ and I am just a bit confused by one of the questions. It asks to give 3 implementations of an overloaded increment operator:
- Using the member function Adjust() which was coded in a previous question.
- Implementing the overloaded operator as a friend function.
- Implementing the overloaded operator as a member function.
Now I understand the concept of overloading the operators I think, that's okay. But I'm actually not too sure about the first one, using the existing member function Adjust(). Because surely if I'm overloading and just calling another function it will either be a friend or a member function calling another member function, if you know what I mean. Anyway, any help would be greatly appreciated. Below is my code for number 2 and 3 just for reference.
//Friend Function
friend Chequebook operator ++(const Chequebook &c); //Declaration in class.
Chequebook operator++(const Chequebook &c) //Function
{
return Chequebook(c.Balance+100);
}
//Member Function
Chequebook operator++(); //Declaration in class.
Chequebook Chequebook::operator++() //Function.
{
return Chequebook(Balance+100);
}
Sorry for the errors in the code. This is supposed to be a pre-increment operator overload.