如何启用/禁用在常量数组中包含元素?在常量数组中启用或禁用元素
struct country {
const string name;
ulong pop;
};
static const country countries[] = [
{"Iceland", 800},
{"Australia", 309},
//... and so on
//#ifdef INCLUDE_GERMANY
version(include_germany){
{"Germany", 233254},
}
//#endif
{"USA", 3203}
];
在C语言中,你可以使用#ifdef来启用或阵列中的禁用特定元素, 但你会怎么做,在d?
typo:include_germary。除非germary是lang,否则无效。的germar。 Germar,这个重要的国家^^ –
固定:) 此外,我应该提到'include_germany'预计是一个常数,而不是一个版本,所以它应该使用'const' /'enum'声明。请参阅下面的@BBaz'答案,以使其与'-version'配合使用。 –
不幸的是,这不会编译... – user1461607