Pergunta

I want an associative array in d programming language. The key is a struct with two shorts. Easy so far.

struct kie { short a; short b; }
short[kie] possibles;

Problem is I want to hold more than value per key. Dynamic would be useful so it can grow and shrink per key When I try to allocate a dynamic array as value to a to key i.e

short[] temp; ... possibles[k] = temp;

I get the understandable error su.d(30): Error: cannot append type short[] to type short

How do I declare an associative array where the values can be a dynamic array of numbers?

Foi útil?

Solução

In general Value[Key] is an associative array that maps values of type Key to values of type Value. If you want a map of kie to short[] then you need to declare exactly that:

short[][kie]

That should do the trick.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top