27 lines
448 B
C++
27 lines
448 B
C++
#include <iostream>
|
||
|
||
using namespace std;
|
||
|
||
// 增强的结构体(c 中结构体中只有变量)
|
||
struct Person
|
||
{
|
||
int pid;
|
||
int age;
|
||
void show() // C++ 的结构体中可以加函数
|
||
{
|
||
// 可以访问同一结构体内的成员变量
|
||
cout << "pid = " << pid << ", age = " << age << endl;
|
||
}
|
||
};
|
||
|
||
int main()
|
||
{
|
||
Person p1 = {1001, 21};
|
||
p1.show();
|
||
|
||
Person p2 = {1002, 19};
|
||
p2.show();
|
||
|
||
return 0;
|
||
}
|