Answer the question
In order to leave comments, you need to log in
How to understand the class constructors and the initialization of variables in it, what is the difference?
1st option:
class Token_stream {
public:
Token_stream() : buffer(0), full(false) {}
void putback(Token t);
Token get();
private:
Token buffer;
bool full;
};
Token_stream ts;
class Token_stream {
public:
void putback(Token t);
Token get();
private:
Token buffer = 0;
bool full = false;
};
Token_stream ts;
class Token_stream {
public:
Token_stream() {
buffer = 0;
full = false;
}
void putback(Token t);
Token get();
private:
Token buffer;
bool full;
};
Token_stream ts;
Answer the question
In order to leave comments, you need to log in
Is there any difference?
bool full = false;
is performed for any constructor that does not have a full field listed in the initialization list. And why doesn't the constructor work like this:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question