Reference

Reference are pointers that are automatically dereferenced

Great.

That's what vb.net really used isn't it?

Why not declare reference then rather than pointers?

When we are building high level program, we shouldn't deal with pointers directly do we?
Two reasons: you can't change a reference, and references do not invoke polymorphism like pointers do.
Yes vb.net prefabbes destructors, and releases dynamically allocated memory automatically. I personally think this is a good thing so long as I don't want to overload those destructors to do anything useful.

Your second question; sometimes you need to pass the value pointed to and sometimes the address is enough. By and large passing an address is faster then passing a real value so that's one good reason to deal with pointers instead of real values. For example, I have a string that is one hundred chars long, I could pass one hundred chars recursivley or I could take advantage of the lack of "Compiler Supervision" and throw a single address at it that will troll itself all the way to the NULL termination. We tend to like the second option.
zhuge wrote:
...references do not invoke polymorphism like pointers do.


References to Base classes do invoke polymorphic behaviour same way pointers to base classses do
As for Zhuge first reason you can't change a references. Well in vb.net you can

when you say car1=car2 in vb.net (or set car1=car2 in vb6), what you do is not calling the copy constructor of Car(car2) and then assign that to car1. What you did is simply pointing car1 reference to car2.

In C++ you can't do that isn't it?

T& hello; // that's not even allowed except when declaring function argument isn't it?


For computergeek01 answer

I think I sort of start figuring out. Yea both reference and pointers are pointers. Except that we do not need to bother putting *.
Topic archived. No new replies allowed.