Forward Reference
ketmar via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Oct 9 12:29:03 PDT 2014
On Thu, 09 Oct 2014 19:04:55 +0000
Anibal via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
wrote:
> Hi everyone,
>
> I'm trying to something like a tree structure.
>
> The following:
>
> import std.container;
> class Tree
> {
> private SList!Tree subTree;
> }
>
> Produces: class Tree no size yet for forward reference.
>
> How i should proceed in order to keep this declaration?
do you really need single-linked list for that? D has dynamic arrays,
which can be used instead.
class Tree {
private Tree[] subTree;
}
you can append items to dynamic array with "~=", get it length
with .length and so on.
seems that you trying to copy some C code (or writing in C
manner), amirite? it is possible to use D as "better C", but D has alot
more to offer. did you seen this excellent book:
http://ddili.org/ders/d.en/ ?
it will teach you some nice things which are absent in C. read it even
if you are seasoned C programmer. you'll see a joy of dynamic arrays,
slices, ranges and templates, nicely explained.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20141009/f8fbcd2e/attachment.sig>
More information about the Digitalmars-d-learn
mailing list