Code below produces this error:
class HASHTABLE
{
public:
const int DIMENSION = 10;
struct NODE
{
char* INFO;
NODE* LINK;
};
NODE arr1[DIMENSION];
};
int main()
{
const int dimension=10;
struct node
{
char* info;
node* link;
};
node arr2[dimension];
};
So, code in int main()
gives no errors, but code in class HASHTABLE
when i declare NODE arr1[DIMENSION];
I get error: int(10) a nonstatic member reference must be relative to specific object.
The solution is obvious, just put static const int DIMENSION = 10;
and I get no errors.
But for how much I understand C++, this code in main
and in class
are the same.
Can someone explain what happens behind the scene?
Also, I hope I understand this:
If I declare DIMENSION
as a static, every object I create using HASHTABLE
will have also the same DIMENSION
, but I thought that was secured via using const
?