I created an array with the length of x but I get the error
invalid use of non-static data member Test::x.
I tried to replace int newArray[x]; with int newArray = new int[x]; but still didn't work out.
When I declared the newArray[x] in the constructor or put static const before int x = 10, the code run successfully.
Why is that?
#include <iostream>
#include <vector>
using namespace std;
class Test
{
private:
int x = 10;
int newArray[x];
public:
Test();
~Test();
};
int main()
{
return 0;
}