28 lines
466 B
C++
28 lines
466 B
C++
|
// 多个对象的构造和析构
|
||
|
// 初始化列表
|
||
|
#include <iostream>
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
class A
|
||
|
{
|
||
|
private:
|
||
|
int x, y, z;
|
||
|
// char *name;
|
||
|
string name; // char * 建议替换为 string
|
||
|
|
||
|
public:
|
||
|
A(int x, int y, int z, const string &name) : x(x), y(y), z(z), name(name) {}
|
||
|
void show()
|
||
|
{
|
||
|
cout << x << ", " << y << ", " << z << ", " << name << endl;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
A a1(10, 20, 4, "disen");
|
||
|
a1.show();
|
||
|
return 0;
|
||
|
}
|