Re: declare array in a class
What error do you get ?
If your variable is static then use :
Code:
float myClass::spec[] ={...}
otherwise remove the "[]" in the initialisation.
Re: declare array in a class
my variabile is not static; but I have only instance of myClass in my program...and the only one instace of spec.....
I know that I can init an array with '{ }' only when I declare it....
Re: declare array in a class
If I declare it static is OK; but I'd like to do it not static:
Quote:
Originally Posted by fullmetalcoder
otherwise remove the "[]" in the initialisation.
if I remove [] from initialization 'spec = {1,2,2,0};' , get an error:
Code:
error C2059: syntax error : ']'
error C2143: syntax error : missing ';' before '{'
error C2143: syntax error : missing ';' before '}'
But is it possible to do this? Thanks
Re: declare array in a class
In the constructor you will have to declare each element of you array seperately.
Code:
spec[0]=.4f;
spec[1]=.4f;
spec[2]=.4f;
spec[3]=1;
of course you could employ a loop to make it easier.
You might then want to develop a constructor that will receive the values in as four arguments.
Re: declare array in a class
I hoped there was a way to don't inittialize array element serarately or with for.....
Thanks