0
votes

I have a two operator with the same operator*.One of the get two class parameter and the other gets 2 class parameter and one integer value.Also I want to use assignment operator.I got an error.All of them implemented in header file.Here is codes.

A& operator*(A& a1, A& a2)

A& operator*(A& a1, A& a2,int x)

I got too many parameters for this operator function error for the above.

operator=must be member functon for that: A& operator=(A& a1, A& a2); How can I fix this problems.

2
@emre Please post your code for the assignment operator and the error that you are seeing.Jonathan Mee
Why does your operator * take 3 parameters? What is it supposed to do with so many parameters?AnT

2 Answers

3
votes

You cannot overload operator* for 3 parameters. The overloaded operator* must either take 0 (pointer overload) or 2 (multiplication overload) parameters.

Even if the code would have been valid, it's still a bad idea to overload operators "non-intuitively". A good rule: overloaded operators should behave as if used with ints.

0
votes

It is hard to figure out what you are trying to do from what you posted, but in any case your operator * declaration makes no sense. In C++ language operator * can be either binary (multiplication) or unary (dereference), which means that in no case it can be declared with 3 parameters.

The same logic applies to assignment operator, which must be a member function that takes 1 argument.

It is not clear from your description why you are trying to declare operator * with 3 parameters.