qfedu-cpp-level/day2/d12.cpp

27 lines
448 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}