I’m new to C++ and need some syntax help.
Can someone help me figure out why my constructor isn’t working? I’m creating an implementation of the Stack class, except my primeStack only stores prime numbers. I want default value of 25.
I get an error whenever I declare a new primeStack object without passing in any value. Shouldn’t the 25 work as a default??
In .h file:
primeStack(unsigned int size=25);
In primeStack.cpp:
primeStack::primeStack(unsigned int size=25)
{
this->size = size;
data = new int[size];
top = 0;
}
Make implementation and definition with exactly the same prototype, and write the variable name for the default parameter as well. Thus
And include the default parameter in the header file. Compiler takes the value from there at compile time.