Help me port line of code with "operator"
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Help me port line of code with "operator"

  1. #1
    Join Date
    Jul 2008
    Posts
    13

    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++;

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,131

    Re: Help me port line of code with "operator"

    Why don't you ask in a C# forum?

  3. #3
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,994

    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
    }

  4. #4
    Join Date
    Jul 2008
    Posts
    13

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center