C++ does not support variable length arrays; either you are not using C++ or you are using an implementation-specific language extension.
In C++ you should use std::vector
for a dynamically sized array.
If you need to access it from multiple functions you can:
- have the functions that need access to the
vector
take a reference to it as an argument, or - make the
vector
a class member variable and make all the functions that need to access it member functions of the class.
Which one makes more sense depends on what, exactly, you are trying to do.
manpreet
Best Answer
2 years ago
I've created a variable length array in one function, however I need to refer to this array in a second function. The problem occurs when I put the declaration above main() seeing as its length hasn't been defined yet, my compiler gets angry.
How does one typically go about this?
EDIT:
Here is my code so far.
I need to make the array's name[] midterm[] and final[] global. They're all in student_input().