摘要: 示例代码 #include "iostream" //operator+ using namespace std; class A{ public: int m_age; public: A(){} A(int age):m_age(age){} // A operator+(const A &a) 阅读全文
posted @ 2024-07-17 16:17 一个小笨蛋 阅读(4) 评论(0) 推荐(0) 编辑
摘要: 浅拷贝与深拷贝的区别 浅拷贝:简单的赋值拷贝操作 深拷贝:在堆区重新申请空间,进行拷贝操作 默认情况下对象拷贝是浅拷贝(深拷贝要自己实现拷贝函数) class Person { public: //无参(默认)构造函数 Person() { cout << "无参构造函数!" << endl; } 阅读全文
posted @ 2024-07-17 15:29 一个小笨蛋 阅读(2) 评论(0) 推荐(0) 编辑
摘要: 助记 关于 this: this 相当于 * const this; //指向不可更改 关于cstring(常量指针): 指向可以更改,指向的内容不可以更改 string hello = "hello"; string hello2 = "hello2"; const char * hello = 阅读全文
posted @ 2024-07-17 15:17 一个小笨蛋 阅读(2) 评论(0) 推荐(0) 编辑