Fork me on GitHub
上一页 1 ··· 86 87 88 89 90 91 92 93 94 ··· 119 下一页
摘要: c++编译器至少给一个类添加四个函数: 构造函数 析构函数 拷贝构造函数,对属性进行值拷贝; 赋值运算符,对属性进行值拷贝; #include<iostream> using namespace std; class Person { public: Person(int age) { m_Age 阅读全文
posted @ 2019-12-25 17:47 西西嘛呦 阅读(255) 评论(0) 推荐(0)
摘要: 注释:选定要注释的区域:ctrl+K,然后再ctrl+C。 解注释:选定要注释的区域:ctrl+K,然后再ctrl+U。 阅读全文
posted @ 2019-12-25 17:42 西西嘛呦 阅读(7403) 评论(0) 推荐(2)
摘要: #include<iostream> using namespace std; class MyInteger { friend ostream& operator<<(ostream& cout, MyInteger myInteger); public: MyInteger() { num = 阅读全文
posted @ 2019-12-25 17:23 西西嘛呦 阅读(761) 评论(0) 推荐(1)
摘要: #include<iostream> using namespace std; class Person { //利用友元使得该函数可以调用到私有的成员变量 friend ostream & operator<<(ostream& cout, Person& p); public: //构造方法,由 阅读全文
posted @ 2019-12-25 16:39 西西嘛呦 阅读(673) 评论(0) 推荐(0)
摘要: 比如我们想要进行对象相加: #include<iostream> using namespace std; class Person { public: int a; int b; //通过成员函数重载加号运算符 Person operator+(Person& p) { Person tmp; t 阅读全文
posted @ 2019-12-25 16:04 西西嘛呦 阅读(168) 评论(0) 推荐(0)
摘要: 客厅:客人可以随意走动;卧室:只有自己能进去; 现在想要自己的好朋友可以进去,就需要用到友元技术。即友元的目的就是让一个函数或者类访问另一个类中私有成员。 关键字:friend 三种实现方法: 全局函数做友元 类做友元 成员函数做友元 全局函数做友元: #include<iostream> usin 阅读全文
posted @ 2019-12-25 14:20 西西嘛呦 阅读(258) 评论(0) 推荐(0)
摘要: class Person{}; 你忘了在定义类之后加上;。 阅读全文
posted @ 2019-12-25 13:37 西西嘛呦 阅读(851) 评论(0) 推荐(0)
摘要: 常函数: 成员函数后加const后我们称这个函数为常函数; 常函数不可以修改成员属性 成员属性声明时加关键字mutable后,在常函数中依然可以修改 常对象: 声明对象前加const 常对象只能调用常函数 常函数: #include<iostream> using namespace std; cl 阅读全文
posted @ 2019-12-25 13:12 西西嘛呦 阅读(1404) 评论(0) 推荐(1)
摘要: #include<iostream> using namespace std; class Person { public: int age; void showClass() { cout << "这是Person类" << endl; } void showAge() { //解决方法,如果是空 阅读全文
posted @ 2019-12-25 12:54 西西嘛呦 阅读(272) 评论(0) 推荐(1)
摘要: this指针指向被调用的成员函数所属的对象。 this指针是隐含每一个非静态成员函数内的一种指针。 this指针不需要定义,直接使用即可。 用途: 当函数的形参和成员变量名重名时,可以用this进行区分。 在类的非静态成员函数中返回对象本身,可使用return *this。 #include<ios 阅读全文
posted @ 2019-12-25 12:46 西西嘛呦 阅读(239) 评论(0) 推荐(0)
上一页 1 ··· 86 87 88 89 90 91 92 93 94 ··· 119 下一页