如何啓用/禁用在常量數組中包含元素?在常量數組中啓用或禁用元素
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