c++ - passing an array of structs to a function and changing it through the fucntion -


so code wont compile reason.

error 3 error c2036: 'pjs *' : unknown size error 4 error c2100: illegal indirection
error 5 error c2037: left of 'size' specifies undefined struct/union 'pjs'

void initarray(struct pjs* array) {      (*array[1]).size = 1; } struct pjs{  char* name;  int size;  int price; }; int main(int argc , char** argv) {     struct pjs array[10];     initarray(array);     system("pause");     return (0); } 

following may help:

struct pjs{     char* name;     int size;     int price; };  // safer use 1 of following declaration // void initarray(pjs *array, std::size_t size) // simpler // void initarray(pjs (&array)[10]) // more restrictive unintuitive syntax void initarray(pjs* array) {     array[1].size = 1; }  int main() {     pjs array[10];     initarray(array); } 
  • definition of pjs should given before use (or requiring size).
  • array[1] pjs *array[1] illegal (as pjs no have operator*)

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -