Accessing ref class when operator -> is redefined

Hi,
i know this is probably a silly question, but the fact is i can't realize how to do this.
I have a ref class with operator -> redefined, but in a specific point of my code i want to acces a member of this class.

Example:

class N2
{
public:
N2(NativeClass nc);
};

ref class RC
{
public:
...
NativeClass* operator -> () {return m_p;}

static operator N2(RC^ rc) {return N2( *(rc->m_p) ); }

private:
NativeClass* m_p;
};

Since i can only acces the class with -> the conversion operator to N2 doens't compile. Any help
Thank you.


Answer this question

Accessing ref class when operator -> is redefined

  • ClaireS

    You can make the function friend :)


  • G20

    You can use a tracking reference to accomplish this.

    static operator N2(RC% rc) {return N2( *(rc.m_p) ); }


  • msdnuser06

    Thankyou Brian,
    That solution compiles but i can't make this:

    N2 n2;
    RC^ rc= gcnew RC;
    n2=rc; <--error, no conversion found.



  • Mark B .

    Sarath, I unmarked your post as an answer. You can elaborate on how you would have solved the problem if you feel differently. Thanks.
  • FergusLogic

    Yeah. Switching to a tracking ref isn't the best solution is it. Try this:

    static operator N2(RC^ rc) {return N2( *((*rc).m_p) ); }


  • Accessing ref class when operator -> is redefined