-
March 8th, 2013, 05:18 AM
#1
Help me port line of code with "operator"
Hi! I need to rewrite this from C++ to C#
Code:
FORCEINLINE bool operator == (const edge2f &other) const
{
return (_vids[0] == other._vids[0] && _vids[1] == other._vids[1]);
}
FORCEINLINE - I can ignore this, but is there some representation of "operator" in C#?
As I understand, this part of code hooks up somewhere into if...else comparison, and does extra check as defined, if comparison operator == is used. Is there some equivavent of this in C#?
Or in C#, I need to define custom function like
bool ExtraCheck(const edge2f &other)
{
return (_vids[0] == other._vids[0] && _vids[1] == other._vids[1]);
}
and use it like this all the time?
if (ExtraCheck(edge,_vids));
I hope I can write some clean solution as we can in C++;
-
March 8th, 2013, 08:08 AM
#2
Re: Help me port line of code with "operator"
Why don't you ask in a C# forum?
-
March 8th, 2013, 09:33 AM
#3
Re: Help me port line of code with "operator"
This is basically a c++ question, he wants to know what this does in c++ so he can write equivalent code in c#
what this does is called operator overloading. It is synactic sugar for an == type test with the defining class as left hand and a const edge2f& as the right hand.
it's unclear what the "left" side of the operator is since you didn't list the class. What it does is
Code:
// Assuming these are defined somewhere in the code....
LeftSide ls; // instantiate a LeftSide object (whatever the class is this operator was defined in)
edge2f edge; // instantiate an edge2f object
if (ls == edge) // results in -> if (ls.operator==(edge))
// note, the == is part of the functionname, it could also be something like ls.IsEqual(edge)
{
// equal
}
else
{
// not equal
}
-
March 8th, 2013, 10:34 AM
#4
Re: Help me port line of code with "operator"
Thank you very much, seems like my original thought was misleading, but now I see what it does exactly and can port it. It is very good to know names of such things, and now I can also google " operator overloading " for C# and find all relevant topics I need.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|