L
luckboyrocky
For the Student class that follows, I'd like to initialize the _scores
vector also as part of the constructor. How do I modify the
initialization list for this? Basically, I don't want to add this code
to the constructor body, and would like to keep the constructor body
empty, and do all initialization as part of the initialization list.
The initialization I had in mind was something like this:
vector<unsigned int> _scores(5, 0); // Vector of five zeroes.
Any ideas?
Thanks,
Xael Banes
class Student {
private:
string _name;
unsigned int _roll_number;
vector<unsigned int> _scores;
public:
Student(string name, int roll_number) :
_name(name), _roll_number(roll_number) { }
};
class Student {
private:
string _name;
unsigned int _roll_number;
vector<unsigned int> _scores;
public:
Student(string name, int roll_number) :
_name(name), _roll_number(roll_number) { }
};
vector also as part of the constructor. How do I modify the
initialization list for this? Basically, I don't want to add this code
to the constructor body, and would like to keep the constructor body
empty, and do all initialization as part of the initialization list.
The initialization I had in mind was something like this:
vector<unsigned int> _scores(5, 0); // Vector of five zeroes.
Any ideas?
Thanks,
Xael Banes
class Student {
private:
string _name;
unsigned int _roll_number;
vector<unsigned int> _scores;
public:
Student(string name, int roll_number) :
_name(name), _roll_number(roll_number) { }
};
class Student {
private:
string _name;
unsigned int _roll_number;
vector<unsigned int> _scores;
public:
Student(string name, int roll_number) :
_name(name), _roll_number(roll_number) { }
};