-1

Just a question: how do you define a new operation for a c++ primitive type?

I have defined a new class (A) and I have overloaded that operation *

So:

A test();
test * 2; //works
2 * test; //doesn't work 
user2934164
  • 193
  • 12

1 Answers1

1
struct A {
    // ...

    friend A operator * (A const& lhs, double rhs);
    friend A operator * (double lhs, A const& rhs);
};
Nevermore
  • 1,127
  • 9
  • 12