- 博客(10)
- 收藏
- 关注
原创 等于=运算符重载
#include<iostream> using namespace std; class person { public: person(int a) { age = new int(a); } person& operator=( person& p) { if (age != NULL) { delete age; age = NULL; } age = new int(* p.age); return *this; }
2020-09-02 16:57:04
1403
原创 c++左移运算符、右移运算符重载
#include<iostream> using namespace std; class person { friend ostream& operator<<(ostream& cout, person& p); public: person(int a, int b) { m_a = a; m_b = b; } private: int m_a; int m_b; }; ostream& operator<<(os
2020-09-01 15:00:31
1149
原创 c++加号+运算符重载
#include <iostream> using namespace std; class person { public: person operator+(person& p)//成员函数重载 { person temp; temp.m_a = this->m_a + p.m_a; temp.m_b = this->m_b + p.m_b; return temp; } int m_a; int m_b; }; /*person operato
2020-09-01 08:47:42
894
原创 递增运算符
#include<iostream> using namespace std; class person { friend ostream& operator<<(ostream& cout, person p);//声明友元全局函数,使得该函数可以访问私有成员属性age public: person& operator++()//前置递增++p,这里person后面跟随一个&,是因为要执行++(++p)操作必须得是同一个对象
2020-08-11 16:06:37
295
原创 浅拷贝带来的问题以及用深拷贝解决方案
**//浅拷贝带来的问题** #include<iostream> using namespace std; class person { public: person(int a,int b) { age = a; shengao = new int(b);//在堆区开辟新的空间 cout << "1.有参、普通构造函数" << endl; } person(const person&am
2020-08-02 16:00:34
591
原创 构造函数调用规则
#include<iostream> using namespace std; class person { public: //c++编译器会帮你在一个类中添加三个函数(默认构造函数、默认析构函数、默认拷贝构造函数) person()//默认无参构造函数,如果自己不写这个构造函数,那么test01中 定义person p1(10);后 person p;就会报错, //因为c++就不在提供默认无参构造函数,但还是会提供默认拷贝构造函数,即定义person p2(
2020-08-02 10:29:11
327
原创 构造函数的分类以及调用时机,析构函数的调用时机
#include<iostream> using namespace std; class person { public: person()//我们可以发现,不管是下列哪三种方法,无参、普通(默认)构造函数都是person p; { cout << "1.无参、普通构造函数" << endl; } person(int a) { age = a; cout << "2.有
2020-08-02 10:08:14
521
1
原创 冒泡排序
//从小到大排五个已知数据的值** #include<iostream> using namespace std; int main() { int a[5] = { 5,4,3,2,1 }; for (int i = 0; i < 5; i++)//有n个数排序,就需要n-1趟排序过程 { for (int j = 0; j < 4 - i; j++)//每次排...
2020-08-02 09:55:14
202
原创 三种参数传值方式
#include<iostream> using namespace std; void jh1(int x, int y) //值传递 { int temp = x; x = y; y = temp; cout << "交换后,jh1函数中 a=" << x << endl; cout << "交换后,jh1函数中 b=" << y << endl; } void jh2(int*
2020-08-01 14:34:22
778
原创 电话联系人管理界面
#include<iostream> #include<string> using namespace std; #define max 200 //表示这个通讯录管理系统最多存储200个联系人 struct lxr //创建联系人数据类型 { string name; //姓名 int age; //年龄 int haoma; //电话号码 string xb; //性别 }; void show() //界面展示,让人知道管理界面有哪些功
2020-08-01 14:31:29
314
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅