Reputation: 311
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.
Upvotes: 0
Views: 139
Reputation: 320481
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.
Upvotes: 0
Reputation: 56547
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 int
s.
Upvotes: 3