I was reading a C++ code line. I encountered a weird code line where a variable was used as a function with a 0 as its parameter!
template <class T> class Stack {
T data[50];
int nElements;
public:
//This line is where the variable was used like a function!
Stack() : nElements(0){}
void push(T elemen);
T pop();
int tamanho();
int isEmpty();
};
So what does exactly mean when we have: the constructor : private variable (0){}
This code line was very weird for me! Thanks
In the initializer_list of Stacks constructor, class member nElements is initialized with a value of zero upon creation of each Stack object.
The value 0 does not have any special meaning here, other than setting the initial number of elements for the Stack to zero as soon as it gets created and is empty.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With