I was trying to make an array of class, but Visual Studio is showing an error Compiler Error C2131
which means "An expression declared as const or constexpr didn't evaluate to a constant at compile time. The compiler must be able to determine the value of the expression at the point it's used."
#include <iostream>
using namespace std;
class instructor
{
public:
string name;
};
int main(void)
{
const int num=0;
cout << "Enter the number of students: ";
cin >> num;
instructor student[num];
return 0;
}
This being the error shown
Error C2131 expression did not evaluate to a constant
Error (active) E0028 expression must have a constant value
What could be the possible fix for this, rather than dynamic allocation?
NOTE:- But the same code is allowed in GCC code-blocks.