I have a class, and let's called it class myClass
class myClass{
  // some math operations
  myClass get_difference(myClass &b)
  {
       print_operation(*this, b);
       do_something else
       return...
  }
  myClass get_sum(myClass &b)
// pseudocode 
void print_operation(const myClass *a, const myClass &b)
{
     if function == get_sum
         print a << "plus" << b;
     if function == get_difference
         print a << "minus" << b;
}
  // overload cout as well
};
Suppose I called the following
myClass anObject(1,2);
myClass anotherObject(3,4);
anObject.get_sum(anotherObject);
anObject.get_difference(anotherObject);
get_sum / get_difference will call print_operation, but I want to be able to determine the caller so a different output format is used.
Naive approach: Use switch-case Add a new parameter called "id". Give each function (the caller) an id, and use switch-case statements in print_operation.
However, is there an alternative? A more elegant solution?
Thanks.
 
     
     
    