| re: Pointer convension, dot vs. indirection notation
On Sat, 14 Aug 2004 15:43:04 -0700, Casper <casper@jbr.dk> wrote:
[color=blue]
> In a recent posting, my notation was corrected:
>[color=green]
> > tree* prootNode = new tree;
> > tree* psubNode = new tree;
> >
> > prootNode->child = psubNode;
> > psubNode->parent = prootNode;[/color]
>
> struct tree rootNode;
> struct tree subNode;
>
> rootNode.child = &subNode;
> subNode.parent = &rootNode;
>
> Is this due to some general C++ convension/practice or because its
> compiler specific to use indirection? I've seen many compilers
> understanding -> however.
>[/color]
I think you misunderstand. I didn't see the original post, but your code
and the correction are just different code. Your code uses pointers to
structs (hence ->) and the correction uses structs (hence .). These are
just different, it's not a case of one being correct notation and the
other not. I can't say which is right for you, but at a guess your
original code looks more likely, maybe you misunderstood the point that
was being made.
In any case you better learn the difference between something which is a
pointer and something which is not, and when you would use one and when
the other, if you are going to be programming dynamically allocated trees.
john |