T
trying_to_learn
I'm learning consts in C++ and the book says that u have to initialize
non-static consts inside the constructor initializer list, however
"const string* stack[size]" isn't initialized in the constructor
initializor list,instead its initialized inside the constructor main
body using memset.I dont understand this,why isnt this uniform
class StringStack {
static const int size = 100;
const string* stack[size];
int index;
public:
StringStack();
void push(const string* s);
const string* pop();
};
StringStack::StringStack() : index(0) {
memset(stack, 0, size * sizeof(string*));
}
non-static consts inside the constructor initializer list, however
"const string* stack[size]" isn't initialized in the constructor
initializor list,instead its initialized inside the constructor main
body using memset.I dont understand this,why isnt this uniform
class StringStack {
static const int size = 100;
const string* stack[size];
int index;
public:
StringStack();
void push(const string* s);
const string* pop();
};
StringStack::StringStack() : index(0) {
memset(stack, 0, size * sizeof(string*));
}