Operator Overloading in C++/CLI

Started by
3 comments, last by jpetrie 17 years, 5 months ago
Hi All, I am having problems with operator overloading in C++/CLI. I have...

inline MNWMatrix^ operator* (MNWMatrix^ in_matrix)
{
   ... code here
}

Which seems to work fine, but when I try and call it using...

MNWMatrix newMatrix=scaleMatrix * translateMatrix;

I get the compile error... Error 3 Operator '*' cannot be applied to operands of type 'MNW.MNWMatrix' and 'MNW.MNWMatrix' D:\Documents and Settings\rprice\My Documents\Visual Studio 2005\Projects\Terraformer4\Terraformer4\MainForm.cs 1241 Shouldn't operator overloading by handle for managed types be supported? Thanks Rael
Advertisement
I have never programmed in C++/CLI, and does not really have that much experience with C++ either, but to me it seems like operator* needs to take one more argument. If it would be a class method, then one argument would be fine as the first object is passed anyway as the this pointer, but since it is not, you have to specify both objects/references that is to be passed.
The overload must be a static method and must specify both arguments in its parameter list. In particular, you may want to check out section 19.7 of the C++/CLI language specification(ECMA-372).
Quote:Original post by jpetrie
The overload must be a static method and must specify both arguments in its parameter list. In particular, you may want to check out section 19.7 of the C++/CLI language specification(ECMA-372).

Ah, that worked perfectly, thank you!

So, can I ask why there are two formats for doing the same thing?

Thanks
Rael
The nearby sections of the standard talk about, specifically 19.7.1, I think.

This topic is closed to new replies.

Advertisement