- D言語 Part34©2ch.net
223 :デフォルトの名無しさん[]:2015/10/09(金) 21:58:55.85 ID:So4fPMkx - const class A { int a; this(int v) { a = v; } }
このクラスAを値に持つ連想配列を作りたいんだけど、 const(A)[int] hoge = [1: new const A(1)]; hoge[3] = new const A(3); // cannot modify const expression hoge[3] みたいに、初期化はできても代入ができない。 A[int] hoge = cast(A[int])[1: new const A(1), 2: new const A(2)]; hoge[3] = cast(A)new const A(3); てなふうにcastしたら回避できたけど、なんか美しくない。 typeof(new const A(1)).stringof == "const(A)" なのがおかしい気がするんだが。
|