C++ Programming questions

Posted:
in Genius Bar edited January 2014
I am trying to port some code snippets from Windows to OSX,it is something that is run from the console,but I have trouble compiling it-I keep getting one warning a bout a variable,or rather an array being unitialized here is the error message and the code:



unitialized const 'null'



const double *G5i::coordinates(int grade) const {



int ia = 0;



int i, j = 1, gu = gradeUsage();



static const double null[32];







for (i = 0; i < 6; i++) {



if (j == grade) return (gu & j) ? c + ia : null;



if (gu & j) ia += G5i_gradeSize[i];



j <<= 1;



}



return null;



}



I tried to initialize it by using:



for (i = 0; i < 32; i++) {



null[i] = 0.0;



}



but that caused even more problems.





The other question is,if I am not able to compile this,where can a get a good free C++ compiler for Windows2000? Any information would be apppreciated.

Comments

  • Reply 1 of 3
    wmfwmf Posts: 1,164member
    It sounds like you don't understand const. Since the array is const, you can't change it, which is what your loop is trying to do. Try an array initializer, like this:



    static const double null[32] = {0.0, 0.0, ... 0.0};



    BTW, I looked up the answer here:



    <a href="http://www.amman.edu/cpp/Arrays/Arrays.html"; target="_blank">http://www.amman.edu/cpp/Arrays/Arrays.html</a>;
  • Reply 2 of 3
    Yeah,that's what I ended up doing.I understand const,I don't understand why it can't be initialized with a loop.
  • Reply 3 of 3
    [quote]Originally posted by Rick1138:

    <strong>Yeah,that's what I ended up doing.I understand const,I don't understand why it can't be initialized with a loop.</strong><hr></blockquote>



    const objects can't be changed, and can only be set in their instantiation. otherwise the compiler can't guarantee the integrity of their constant-ness. making a loop would force the const[ant] objects to change [out of their instantiation]. constant change == no no.
Sign In or Register to comment.