Dear cplusplus forum members,
when trying to overload the operator < with a non-member function, I get an error such as 'error: too many parameters for this operator function' :
1 2 3 4 5 6 7 8 9 10 11 12
struct MyClass
{
const Alfa alfa;
const Beta beta;
const Gamma gamma;
};
// To order the keys in the map
inlinebooloperator< (const MyClass& a, const MyClass& b)
{
// ...
}
But what is the rationale behind? I mean, the class is already defined, there is no operator< declared, why can the compiler confuse it for an instance method?
I don't see a reason why this should fail if lines 9-12 are not within the MyClass definition. I wonder what would happen if you removed the inline keyword. This causes very specific compile-time things to happen.
Edit: I wouldn't consider this a begginer question so +1 for underestimating yourself.
My compiler works without adding the friend keyword. (I just copied your code to see if the compiler would scream).
Can you give me an example on where you defined it and where you use it?
EDIT: I do believe like Stewbond, that the inline keyword is messing up with your compile units.
RE-EDIT: I suppose that within your operator overload you call the other relational operators for the following struct/classes: Alfa, Beta, Gamma. Did you create member operators for those struct/classes with the appropriate number of parameters?... I think that's why it is messing with you :)
Hi there,
SeiZa thanks for having tried the sample code, you are right! And I am an ape!:)
I extrapolated that piece from some mess, only now I am becoming aware I am inside a class definition, opened somewhere above the error.
The compiler believes the operator is defined for the outer class.