views:

45

answers:

2

I am trying to overload my operators its really just a class that holds arithmetic functions and a sequence of array variables.

But when i am overloading my (*) multiplication operator i get this error:

     binary '*' : no global operator found which takes type 'statistician' 
(or there is no acceptable conversion)

This happens when my code tries to do: s = 2*u;in main.cpp

where s, and u are statistician classes.

statistician = my class

(statistician.h)

class statistician  
{
... other functions & variables...

const statistician statistician::operator*(const statistician &other) const;

..... more overloads...

};

Any help would be awesome thanks!!

+5  A: 

Declare a namespace scope operator*, so that you can also have a convertible operand on the left hand side that is not of type statistician.

statistician operator*(const statistician &left, const statistician &right) {
  // ...
}

Needless to say that you should remove the in-class one then, and you need a converting constructor to take the int.

Johannes Schaub - litb
+4  A: 
Dima