J
jrefactors
I don't understand the usage of constructor initializer list
and when must it be used. I always do code 1 and never do code 2,
but what's the difference between them, and when to use which.
class Student
{
public:
Student();
private:
int _id;
string _name;
};
//code 1
Student::Student(int id, String name)
{
_id = id;
_name = name;
}
//code 2
Student::Student(int id, String name)
: _id(id),
_name(name)
{
}
Please advise. thanks!!
In C++, what are the differences between a class and a struct?
and when must it be used. I always do code 1 and never do code 2,
but what's the difference between them, and when to use which.
class Student
{
public:
Student();
private:
int _id;
string _name;
};
//code 1
Student::Student(int id, String name)
{
_id = id;
_name = name;
}
//code 2
Student::Student(int id, String name)
: _id(id),
_name(name)
{
}
Please advise. thanks!!
In C++, what are the differences between a class and a struct?