在c++中如何调用数组对象的构造函数

来源:百度知道 编辑:UC知道 时间:2024/06/18 15:13:28

#include<iostream>
#include<string>
using namespace std;

//对象数组的初始化请看该函数
class student
{
public:
student(string name)
{
m_strname=name;
}
student(){}
void display()
{
cout<<"student name:"<<m_strname<<endl;
}
private:
string m_strname;
};

void main()
{
student stu[3]={student("zhangsan"),student("lisi")};
stu[0].display();
stu[1].display();
}

//深入了解构造和析构函数过程参看该函数!
#include<iostream>
using namespace std;

class study
{
private:
int num;
public:
study()
{
cout << "study default constructing^" << endl;
}
study(int a)
{
num = a;
cout << "study constructing^ " << num << endl;
}
~study()
{ <