当前位置:网站首页>【类的组合(在一个类中定义一个类)】
【类的组合(在一个类中定义一个类)】
2022-07-24 21:32:00 【李在奋斗……】
【类的组合 :类名A 对象】
(对象名())可不是类名

#include <iostream>
#include <string.h>
using namespace std;
class Person
{
private:
string name;
string sex;
int age;
public:
Person(string na, string se, int ag) :name(na), sex(se), age(ag) {}
Person() {}
~Person() {}
void show()
{
cout << "姓名,性别,年龄为:" << name << " " << sex << " " << age << " " << endl;
}
};
class Student
{
private:
int gress;
Person p;
public:
Student(string na = "李明", string se = "男", int ag = 20, int gr = 11) :p(na, se, ag), gress(gr) {}
void show()
{
p.show();
cout << "级别为:" << gress << endl;
}
};
int main()
{
Student s;
s.show();
return 0;
}

边栏推荐
- [untitled]
- Strong reference, weak reference, soft reference, virtual reference
- Transport layer protocol parsing -- UDP and TCP
- Top 10 in China's HCI software market: Huawei, Xinhua, Shenxin, VMware, Lenovo, smartx, Inspur, Qingyun, lutanli, dawn
- PHP page Jump mode
- Spark related FAQ summary
- Quick sort
- 93. Recursive implementation of combinatorial enumeration
- [jzof] 06 print linked list from end to end
- Can century model simulate soil respiration? Practice technology application and case analysis of century model
猜你喜欢

Node installation using NVM succeeded, but NPM installation failed (error while downloading, TLS handshake timeout)

Native applets are introduced using vant webapp

Mathpix formula extractor

Mitmproxy tampering with returned data

Day5: three pointers describe a tree

C synchronous asynchronous callback state machine async await demo

驱动子系统开发

RESNET interpretation and 1 × 1 Introduction to convolution

ERROR 2003 (HY000): Can‘t connect to MySQL server on ‘localhost:3306‘ (10061)

Preview and save pictures using uni app
随机推荐
climb stairs
250 million, Banan District perception system data collection, background analysis, Xueliang engineering network and operation and maintenance service project: Chinatelecom won the bid
How does redis realize inventory deduction and prevent oversold? (glory Collection Edition)
Use of cache in C #
Merge sort
Evaluation of four operation expressions
From front-line development to technical director, you are almost on the shelf
[basic data mining technology] exploratory data analysis
Five common misuse of async/await
Drive subsystem development
Baidu classic interview question - determine prime (how to optimize?)
Scientific computing toolkit SciPy image processing
ERROR 2003 (HY000): Can‘t connect to MySQL server on ‘localhost:3306‘ (10061)
Mitmproxy tampering with returned data
Intel internship mentor layout problem 1
93. Recursive implementation of combinatorial enumeration
ma.glasnost.orika. MappingException:No converter registered for conversion from Date to LocalDateTime
Intranet penetration learning (I) introduction to Intranet
Go language error handling
Preview and save pictures using uni app