[SOLVED] how to pass an array through to another function? c++


so i am making a program that takes student data as objects and prints it, i am trying to store the data as an array so each student is a element in the array, i am having issues with printing the data though as i cannot pass the array into the print function, can anyone help? when i try and compile i get "studentarray: arrays of references are illegal". sorry if this is a stupid question i am new to coding, thankyou!


You wrote student printstudent(student & studentarray); which looks more like a deceleration than a function call.

I’m guessing you wanted to write printstudent(studentarray)?

Your error is caused by declaring printstudent(student& studentarray[10]) , which declares the function argument to be an array of 10 student& i.e. references to students, which the c++ standard forbids:

There shall be no references to references, no arrays of references, and no pointers to references.

Some more details on why can be found here: Why are arrays of references illegal?

Answered By – Timon van der Berg

Answer Checked By – Willingham (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *