Sign in to follow this  
Raeldor

Operator Overloading in C++/CLI

Recommended Posts

Raeldor    254
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
Lajnold    226
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
Raeldor    254
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this