我有一个类,我正在使用参数化构造函数创建它的一个对象。在此期间,参数化构造函数和默认构造函数都已被调用。
这是我的片段:
class student {
string name;
int age;
public:
student() {
cout << "Calling the default constructor\n";
}
student(string name1, int age1) {
cout << "Calling the parameterized const\n";
name = name1;
age = age1;
}
void print() {
cout << " name : " << name << " age : " << age << endl;
}
};
int main()
{
map<int, student> students;
students[0] = student("bob", 25);
students[1] = student("raven", 30);
for (map<int, student>::iterator it = students.begin(); it …Run Code Online (Sandbox Code Playgroud) c++ class stdmap default-constructor parameterized-constructor