On 03/26/2013 10:28 PM, Joseph Cassman wrote:
I get these errors
aggregate.d(11): Error: variable aggregate.A.c!("y").c cannot use
template to add field to aggregate 'A'
aggregate.d(6): Error: template instance aggregate.A.c!("y") error
instantiating
from compiling the following code
struct A
{
void b()
{
size_t y;
mixin(c!("y"));
}
template c(string x)
{
const char[] c = "
while(" ~ x ~ " < 100)
{
" ~ x ~ "++;
}";
}
}
I can only find bug 276
(http://d.puremagic.com/issues/show_bug.cgi?id=276) which seems related
but looks like it was fixed.
I am using dmd 2.062 on Ubuntu Linux 12.10.
Is this a bug? Or maybe bad code?
Bad code. Use enum for compile-time constants.
This will work:
struct A{
void b(){
size_t y;
mixin(c!("y"));
}
template c(string x){
enum c = "while(" ~ x ~ " < 100){" ~ x ~ "++;}";
}
}