• Advertisement
Sign in to follow this  

Operator Overloading in C++/CLI

This topic is 4121 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
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 this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement