## Recommended Posts

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

##### Share on other sites
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.

##### Share on other sites
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).

##### Share on other sites
Quote:
 Original post by jpetrieThe 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

##### Share on other sites
The nearby sections of the standard talk about, specifically 19.7.1, I think.

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627675
• Total Posts
2978567

• 11
• 11
• 10
• 12
• 22