Is it possible to overload an operator for only one function. I want to override the '->' operator, but only when it is called with the print function ( ->print() ). I understand this is a weird request, but I am working on fulfilling a certain API, and I would need something like this.
For example:
Cat cat;
cat.walk();
cat->print(); //I want to overload only this call
However, I don't want to overload the '->' operator for all cases. For example:
Cat* cat;
cat->walk(); //this should work normally
cat->print(); //this wouldn't call the print() function,
//since I overloaded cat->print()
Cat* cat; cat->print();What exactly would this be supposed to do then? Shouldn't compile or what?->is a pointer, the arrow operator always has its built-in meaning, and nooperator->will change what the expression means.