Pointers
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Sat Feb 14 22:57:07 PST 2009
Eugene Y. wrote:
> class C
> {
> }
>
> If I declare an instance of class C
>
> C cinstance = new C();
>
> is cinstance a pointer or is it like C++?
> I'm wondering this because I tested with DMD 2.008 and if I do this
It is a reference. I'm not sure off the top of my head whether its a
direct pointer or a handle under the hood, but at any rate, its a
pointer to something.
> C dinstance = cinstance;
>
> it doesn't seem to copy by value but by reference just like copying pointers
> in C/C++.
Correct, it only copies the reference/pointer.
> If this is the case, is there any point in having pointers to Classes?
Not in the common case, no, but it can be useful at times. (Although,
most of the cases where I would use them involve parameter passing, so I
just use 'ref' arguments.)
-- Chris Nicholson-Sauls
More information about the Digitalmars-d-learn
mailing list