I got the error: 'DblArray::maxcells': is not a type name, static, or enumerator.
After searching around and finding a similar case, I found the following solution:
DblArray.h:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
usingnamespace std;
constint maxcells = 5; //Moved maxcells declaration to here
class DblArray
{
public:
DblArray();
void Set (int i, double val);
double Get (int i) const;
bool IsSet (int i) const;
private:
// From here
double indexarray[maxcells];
int setrecord[maxcells];
};
I couldn't seem to get it to work without a const, or by making it a static. I'm still not quite clear what the problem is. It's a const when I use it external to the class, so what's the difference? And when I use the constant in the constructor, I'm not really using it as anything but a constant that designates the size of the array. Then I'm assigning values within the array of that size, not to the constant itself. (At least that's what I intended.) Why would the compiler forbid that?