c++ - I need help with properly initlizing a structure and passing it into a function properly -


i writing simple c++ database, using visual studio 2008 express edition, program sort , search text file containing ncaa winners , runner ups year, data saved within structure. understand how sorting , searching having trouble initializing structure , passing function, when try how shown in class several errors have been unable rid of, appreciated.

the errors follows;

project5.cpp(145) : error c2676: binary '[' : 'data' not define operator or conversion type acceptable predefined operator

project5.cpp(145) : error c2228: left of '.year' must have class/struct/union

project5.cpp(146) : error c2676: binary '[' : 'data' not define operator or conversion type acceptable predefined operator

project5.cpp(146) : error c2228: left of '.schoolwin' must have class/struct/union

project5.cpp(147) : error c2676: binary '[' : 'data' not define operator or conversion type acceptable predefined operator

project5.cpp(147) : error c2228: left of '.scorewin' must have class/struct/union

project5.cpp(148) : error c2676: binary '[' : 'data' not define operator or conversion type acceptable predefined operator

project5.cpp(148) : error c2228: left of '.schoolrunnerup' must have class/struct/union

project5.cpp(149) : error c2676: binary '[' : 'data' not define operator or conversion type acceptable predefined operator

project5.cpp(149) : error c2228: left of '.scorerunnerup' must have class/struct/union

project5.cpp(191) : error c2664: 'initializestructure' : cannot convert parameter 1 'data [100]' 'data &'

my structure declaration:

const int size = 100;           // size of structure struct data {                   // struct definintion take in stats     int year;     string schoolwin;     int scorewin;     string schoolrunnerup;     int scorerunnerup; } ncaastats [size] ; void initializestructure(data& ncaastats,  int size);  // initialization function prototype  //function declaration void initializestructure(data& ncaastats,  int size) {     int idx;     (idx = 0; idx < size; idx++) {         ncaastats[idx].year = 0000;//line145         ncaastats[idx].schoolwin = "winning school";//line146         ncaastats[idx].scorewin = 000;//line147         ncaastats[idx].schoolrunnerup = "losing school";//line148         ncaastats[idx].scorerunnerup = 000;//line149     } } //initalize array of structures initializestructure(ncaastats, size);//line 191 function call within main 

based off last error thinking possible reason visual studio thinks structure named data size of 100 when, ncaastats of size 100, not sure did wrong causing this, suggestions appreciated.

you have declared array ncaastats[size] @ global scope. however, functions have arguments called ncaastats; these hide global definition. therefore, stuff ncaastats[idx] invalid, because ncaastats data &, not data[].


Comments