473,387 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Pointers/References

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#?
Nov 17 '05 #1
3 2475

"Maksim" <Ma****@discussions.microsoft.com> wrote in message
news:A3**********************************@microsof t.com...
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.
Nov 17 '05 #2
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.
"Daniel O'Connell [C# MVP]" wrote:

"Maksim" <Ma****@discussions.microsoft.com> wrote in message
news:A3**********************************@microsof t.com...
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.

Nov 17 '05 #3

"Maksim" <Ma****@discussions.microsoft.com> wrote in message
news:1E**********************************@microsof t.com...
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.
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Web Developer | last post by:
Hi, Can someone provide a short and concise statement(s) on the difference between pointers and references. A graphical representation (via links?) of both would be much appreciated as well. ...
4
by: cppaddict | last post by:
I understand that there are a couple differences between reference variables and pointer: 1) reference variables *must* be initialized. 2) You cannot change what a reference variable refers...
26
by: Desmond Liu | last post by:
I've read articles like Scott Meyer's EC++ (Item 22) that advocate the use of references when passing parameters. I understand the reasoning behind using references--you avoid the cost of creating...
7
by: _ed_ | last post by:
I'd like to build a class or struct composed of pointers to variables. Does this require dropping into an 'unsafe' block, or is there a trick? .... int value1 = 1234; bool value2 = false;...
12
by: arganx | last post by:
Before I had a good idea how to use pointers, I was wondering - first, how to use them. And second, of what value would they be. Now that I have at least a pretty good idea of how to use them, I...
458
by: wellstone9912 | last post by:
Java programmers seem to always be whining about how confusing and overly complex C++ appears to them. I would like to introduce an explanation for this. Is it possible that Java programmers...
7
by: Erdal Mutlu | last post by:
Hi, I am trying to design a base class (interface) with two or more subclasses as follows: class A { .... virtual static A* getByName(const string x)=0 const; }
64
by: Zytan | last post by:
I know there are no pointers in C#, but if you do: a = b; and a and b are both arrays, they now both point to the same memory (changing one changes the other). So, it makes them seem like...
19
by: MQ | last post by:
Can someone tell me where I should use pointers and where I should use references? In his book, Stroustrup says that you should use pointers for passing arguments that are to be modified, not...
29
by: Simon Saize | last post by:
Hi - What's the point of having references (&)? Why don't we just use pointers (*)? Thanks.
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.