2个回答
展开全部
例如:
#include <iostream>
using namespace std;
class Person
{
private:
char* name;
int age;
public:
Person(char* name, int age)
{
this->name = name;
this->age = age;
}
void show()
{
cout << "name: " << name << endl;
cout << "age: " << age << endl << endl;
}
};
int main()
{
Person p[3] = {Person("zhangsan", 20), Person("lisi", 21), Person("wanger", 22)};
p[0].show();
p[1].show();
p[2].show();
getchar();
return 0;
}
#include <iostream>
using namespace std;
class Person
{
private:
char* name;
int age;
public:
Person(char* name, int age)
{
this->name = name;
this->age = age;
}
void show()
{
cout << "name: " << name << endl;
cout << "age: " << age << endl << endl;
}
};
int main()
{
Person p[3] = {Person("zhangsan", 20), Person("lisi", 21), Person("wanger", 22)};
p[0].show();
p[1].show();
p[2].show();
getchar();
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询