可能重复:
What is this weird colon-member syntax in the constructor?构造函数设置?
我想明白这是什么样的代码意味着
说我有这个
class OptionStudent: public Student // derived class from Student class
{
public:
explicit OptionStudent(const std::string id = "12345678",
const std::string first = "someone")
: Student(id, first)
{
count_++;
}
}
那是什么在“某人”之后冒号):< - pa rt叫或意味着这个构造?
我知道构造函数可能有点不正确,但我不知道这是叫什么。我只是从教练在教学板上写的内容抄录了笔记,并不理解它。
与类或对象记住某事有关吗?
这是一个初始化列表。 – rightfold