I'm going to take a guess here and say that it has nothing to do with fixed/variable length, but that you're trying to use the variable in a place that doesn't have access to it. You'll have to show us line 46 of Stack.cc for us to have any insights.
You can't call functions (such as new) in your class {..} member variables. Your class {...}does not get executed automatically. It sits somewhere looking pretty so the compiler knows what an object of that class looks like.
If you want the class variable s to be a pointer to a variable length array, you'll have to have that array created using new in a function that gets run. I suggest the constructor.
I'm going to take a guess here and say that it has nothing to do with fixed/variable length, but that you're trying to use the variable in a place that doesn't have access to it. You'll have to show us line 46 of Stack.cc for us to have any insights.
Hope this helps
1 2 3 4 5 6
void Stack::inspect() {
if(empty()) {cout << "The stack is empty" << endl;}
for(int i=0 ; i<count-1; i++){
std:cout << "The value of position " << count-1-i << " is " << s[count-1-i] << endl;
}
}
To clarify, you're trying to implement a stack class that you can pass in the length to, correct?
I'm working towards creating a stack class that I can pass the length to as a constructor argument
If you want the class variable s to be a pointer to a variable length array, you'll have to have that array created using new in a function that gets run. I suggest the constructor