Can structs be used with associative arrays?
Tim Locke
root at vic-20.net
Sat Apr 29 11:07:33 PDT 2006
On Wed, 20 Jul 2005 20:46:26 -0400, "Ben Hinkle"
<ben.hinkle at gmail.com> wrote:
>> int main()
>> {
>> A[char[]] x;
>> x["a"] = *(new A); // Create an instance of the struct.
>> x["a"].a = 1;
>> return( 0 );
>> }
>
>Note the *(new A) will allocate a new A and then copy the contents to x["a"]
>and then throw away the allocated memory. So a way of doing the same thing
>without allocating extra memory is to
> x["a"] = A.init;
What is the concise method of initializing the members of my array of
structs? It seems long-handed to do this:
x["a"].a = 1;
x["a"].b = 2;
etc.
Can this be shortened? According to spec_DMD_0.109.pdf, pages 100-101,
I *think* I should be able to do something like this:
x["a"] = {a:1, b:2};
But the compiler gives me the following error: "expression expected,
not '{'". I also tried replacing {} with () and got "found ':' when
expecting ')'".
Thank you.
--
On the Internet, no one knows you're [using] a VIC-20.
More information about the Digitalmars-d-learn
mailing list