Re: static array of pointers to dynamic arrays of ints problem...

2018-04-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/22/18 2:00 AM, WhatMeForget wrote: Surely a stupid mistake on my part, but why is the first array repeated? In addition to what Neia said, you shouldn't use pointers to dynamic arrays. Such things are really hard to allocate on the heap, since new int[] just makes an array, not a pointer

Re: static array of pointers to dynamic arrays of ints problem...

2018-04-21 Thread Neia Neutuladh via Digitalmars-d-learn
On Sunday, 22 April 2018 at 06:00:15 UTC, WhatMeForget wrote: foreach(i, elem; a) { int[] temp = new int[](5); .. a[i] = &temp; } You're taking the address of a local variable and persisting it beyond the variable's scope. This is not safe in general; compilers

static array of pointers to dynamic arrays of ints problem...

2018-04-21 Thread WhatMeForget via Digitalmars-d-learn
Surely a stupid mistake on my part, but why is the first array repeated? import std.stdio; void main() { int[]*[2] a; // a static arrray holding pointers to dynamic arrays static int unique = 0; foreach(i, elem; a) { int[] temp = new int[](5); foreach(ref e

Re: Array of pointers

2014-01-20 Thread Philippe Sigaud
On Mon, Jan 20, 2014 at 10:58 AM, Andrej Mitrovic wrote: > On 1/16/14, Philippe Sigaud wrote: >> The thing is, an array is a reference type > > Actually it's not, let's not confuse people with the terminology here. > To recap for people new to arrays: an array in D is really just a > struct, e.g.

Re: Array of pointers

2014-01-20 Thread Ali Çehreli
On 01/20/2014 01:58 AM, Andrej Mitrovic wrote: > On 1/16/14, Philippe Sigaud wrote: >> The thing is, an array is a reference type > > Actually it's not, let's not confuse people with the terminology here. > To recap for people new to arrays: an array in D is really just a > struct, e.g.: > > str

Re: Array of pointers

2014-01-20 Thread Andrej Mitrovic
On 1/16/14, Philippe Sigaud wrote: > The thing is, an array is a reference type Actually it's not, let's not confuse people with the terminology here. To recap for people new to arrays: an array in D is really just a struct, e.g.: struct Array { int* data; size_t length; } Array myArray

Re: Array of pointers

2014-01-20 Thread Gary Willoughby
On Saturday, 18 January 2014 at 14:57:39 UTC, Arjan Fetahu wrote: I have some experience with C experience, so I still have to learn tamplates. Thaks for the help. Arjan Here's a handy introduction: http://nomad.so/2013/07/templates-in-d-explained/

Re: Array of pointers

2014-01-19 Thread Arjan Fetahu
Nodes are reference types in D, so probably you don't need to use a * for Node. Alternatively use a struct handled by pointer. "auto content;" can't compile, you need a type, or you have to template Node on T and use it for content. Bye, bearophile Youre right, it compiles now, and the obje

Re: Array of pointers

2014-01-19 Thread bearophile
Arjan Fetahu: Since each Node connects to multiple others i came up with this solution. class Node { auto content; Node*[] nodes; //..constructor.. } Nodes are reference types in D, so probably you don't need to use a * for Node. Alternatively use a struct handled by pointer.

Re: Array of pointers

2014-01-19 Thread Arjan Fetahu
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*[] nod

Re: Array of pointers

2014-01-16 Thread Philippe Sigaud
On Thu, Jan 16, 2014 at 10:47 AM, Rene Zwanenburg wrote: > 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. That's not true. Indeed

Re: Array of pointers

2014-01-16 Thread Namespace
in D (I have a little experience in c). I wanted to create an array of pointers for creating a node with multiple connections. In C you can make one directly (node *nedePtr[]). What is the equivalent for the D's syntax?? Regards Arjan node*[] nedePtr; Ok. Thank You! Keep in mind

Re: Array of pointers

2014-01-16 Thread Rene Zwanenburg
of pointers for creating a node with multiple connections. In C you can make one directly (node *nedePtr[]). What is the equivalent for the D's syntax?? Regards Arjan node*[] nedePtr; Ok. Thank You! Keep in mind that, unlike in c++, D classes are reference types: class Node {

Re: Array of pointers

2014-01-16 Thread Namespace
On Thursday, 16 January 2014 at 08:55:43 UTC, Arjan Fetahu wrote: Hi. I started my first program in D (I have a little experience in c). I wanted to create an array of pointers for creating a node with multiple connections. In C you can make one directly (node *nedePtr[]). What is the

Re: Array of pointers

2014-01-16 Thread Arjan Fetahu
On Thursday, 16 January 2014 at 09:00:18 UTC, Namespace wrote: On Thursday, 16 January 2014 at 08:55:43 UTC, Arjan Fetahu wrote: Hi. I started my first program in D (I have a little experience in c). I wanted to create an array of pointers for creating a node with multiple connections. In C

Array of pointers

2014-01-16 Thread Arjan Fetahu
Hi. I started my first program in D (I have a little experience in c). I wanted to create an array of pointers for creating a node with multiple connections. In C you can make one directly (node *nedePtr[]). What is the equivalent for the D's syntax?? Regards Arjan