Pointers/References

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to imprort an AVL Tree written in C++ to C# and I have a problem
translating this statement: root_parent = (Node *) &this->_Root

I'm using classes for my Nodes and so I can't use '&' with classes. So how
do I write this in C#?
 
Maksim said:
I'm trying to imprort an AVL Tree written in C++ to C# and I have a
problem
translating this statement: root_parent = (Node *) &this->_Root

I'm using classes for my Nodes and so I can't use '&' with classes. So how
do I write this in C#?

something like

root_parent = this._Root;

C# classes are already reference types, that is the varaible you are using
is holding a reference to the instance, not the instance itself, so there is
no need to take the address of a class and don't have to play the pointer
game.
 
That's what I did (root_parent = this._Root;) when I first saw the statement
root_parent = (Node *) &this->_Root and it didn't work. I realized that _Root
is a pointer and &this->_Root gets the address of that pointer.

Hope I stated my problem clear now.
 
Maksim said:
That's what I did (root_parent = this._Root;) when I first saw the
statement
root_parent = (Node *) &this->_Root and it didn't work. I realized that
_Root
is a pointer and &this->_Root gets the address of that pointer.

Hope I stated my problem clear now.

I'm sorry, but that code is not directly translateable as C# has no concept
of reference-to-reference variables. You will have to modify the code so
that it works under a different ruleset than the C++ one did.
 
Back
Top