Array of pointers
Arjan Fetahu
21arjan at hotmail.com
Sat Jan 18 03:25:39 PST 2014
>> Keep in mind that, unlike in c++, D classes are reference
>> types:
>>
>> class Node
>> {
>> Node[] nodes; // This is valid
>> }
>>
>> Structs are value types though, so using a struct in the above
>> example is illegal.
>
> You mean:
> ----
> struct Node {
> Node[] nodes;
> }
> ----
>
> or
>
> ----
> struct Node {
> Node*[] nodes;
> }
> ----
>
> ? Works both.
>
> What's not working is this:
> ----
> struct Node {
> Node node;
> }
> ----
I wanted to heap allocate Nodes which connect to each other via
pointers. Since each Node connects to multiple others i came up
with this solution.
class Node {
auto content;
Node*[] nodes;
//..constructor..
}
More information about the Digitalmars-d-learn
mailing list