以下声明:
const(string[char]) AA1 = [
'a' : "fkclopel",
'b' : "poehfftw"
];
void main(string args[]){}
给我:
C:... \ temp_0186F968.d(1,27):错误:非恒定表达式['a':“ fkclopel”,'b':“ poehfftw”]
同时可以与其他类型一起使用。
您可以在模块构造函数中初始化关联数组常量:
const /+ or immutable +/ (string [char]) AA1;
static this () {
AA1 = [
'a' : "fkclopel",
'b' : "poehfftw"
];
}
import std.stdio;
void main () {writeln (AA1);}
关于关联数组文字的手册部分明确指出:“不能使用AssocArrayLiteral来静态地初始化任何内容。”尽管它并未提供有关这样做的线索。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句