|
- #include <iostream>
-
- using namespace std;
- class Student
- {
- private:
- int id;
-
- public:
- Student(const int a) {
- id = a;
- cout<<"Constructor"<<endl;
- }
-
- Student(const Student & stu) {
- id = stu.id;
- cout<<"Copy Function"<<endl;
- }
- ~Student() {
- cout<<"Destructor"<<endl;
- }
-
- void print(Student stu){
- cout<<stu.id<<endl;
- }
- void print(){
- cout<<id<<endl;
- }
- friend void print1(Student stu);
- };
- void print1(Student stu){
- cout<<stu.id<<endl;
- }
复制代码
题目要求实现类似于下面的输出格式:
输入:
a b
输出:
Constructor
stu1
a
Copy Function
a
Destructor
stu2
Constructor
b
Destructor
Copy Function
stu3
a
Copy Function
a
Destructor
Destructor
Destructor
为什么我在编写主函数的时候无法实现这样的格式呢?要求补全主函数,利用类中的函数,实现以下样例的输出,其中只有stu1,stu2,stu3使用cout输出。 |
上一篇: 一道静态联编和动态联编的题下一篇: C++菜鸟
|