摘要: 代码1 int main(){ //裸指针,手动开辟,需要自己释放,如果忘记了或者因为 //程序逻辑导致p没有释放,那么就会导致内存泄漏 int *p=new int(10); if(***){ retur -1; } delete p; return 0; } 有没有什么办法帮我们管理指针,确保资 阅读全文
posted @ 2022-12-02 15:19 Hello_Bugs 阅读(87) 评论(0) 推荐(0) 编辑
摘要: 代码1 #include <iostream> #include <functional> #include<cstdio> #include<cstring> using namespace std; class MyString3 { public: MyString3(const char * 阅读全文
posted @ 2022-12-01 17:28 Hello_Bugs 阅读(49) 评论(0) 推荐(0) 编辑
摘要: 代码1 using namespace std; class TestV2 { public: TestV2(int a = 10) : ma(a) { cout << "TestV2(int) " << ma <<" 对象地址="<<this << endl; } ~TestV2() { cout 阅读全文
posted @ 2022-12-01 12:11 Hello_Bugs 阅读(45) 评论(0) 推荐(0) 编辑
摘要: 代码1 #include <iostream> using namepspace std; class Test { public: Test(int a=10):ma(a){cout<<"Test()"<<endl;} ~Test(){cout<<"~Test()"<<endl;} Test(co 阅读全文
posted @ 2022-12-01 09:55 Hello_Bugs 阅读(54) 评论(0) 推荐(0) 编辑
摘要: C语言中我们使用 int a=(int) b;的方式强制转换 C++提供了四种类型转换方式 const_cast 通过const_cast运算符,也只能将const type转换为type,将const type&转换为type&。 也就是说源类型和目标类型除了const属性不同,其他地方完全相同 阅读全文
posted @ 2022-11-30 10:22 Hello_Bugs 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 代码1 #include <iostream> using namespace std; class A{ public: A(int _a):ma(_a){ cout<<"A()"<<endl; } ~A(){ cout<<"~A()"<<endl; } protected: int ma; }; 阅读全文
posted @ 2022-11-29 21:51 Hello_Bugs 阅读(72) 评论(0) 推荐(0) 编辑
摘要: 虚基类/抽象类 抽象类:有纯虚函数的类 代码1 class A{ public: int ma; protcted: int mb; private: int mc; } //B继承 A, class B : public A{ public: int md; potected: int me; p 阅读全文
posted @ 2022-11-29 15:16 Hello_Bugs 阅读(122) 评论(0) 推荐(0) 编辑
摘要: 理解多态 多种多样的形态(静态多态,动态多态) 静态多态(编译时期) 1:函数重载 bool comparet(int ,int); bool compare(double,double); compare(100,100)->compare_int_int(); compare(1.0,2.0)- 阅读全文
posted @ 2022-11-28 15:15 Hello_Bugs 阅读(62) 评论(0) 推荐(0) 编辑
摘要: 抽象类和普通类有什么区别? 抽象类一般不用作抽象实体类型 一般把上面类设计为抽象类? 基类 定义抽象类的唯一目的, 就是去建立派生类. 我们在抽象类基础上要定义出功能各异的派生类, 再用这些派生类去建立对象. 凡是包含纯虚函数的类都是抽象类. 纯虚函数不用实现, 故不能被调用, 抽象类无法建立对象. 阅读全文
posted @ 2022-11-28 14:06 Hello_Bugs 阅读(67) 评论(0) 推荐(0) 编辑
摘要: 问题:是不是虚函数的调用就一定是动态绑定?不是的 1:在类的构造函数当中,调用虚函数,也是静态绑定(构造函数中对虚函数的调用不发生动态绑定) 2:如果不是通过指针或者引用变量来调用虚函数,那就是静态绑定 代码1 class Base { public: Base(int data=10):ma(da 阅读全文
posted @ 2022-11-28 11:13 Hello_Bugs 阅读(72) 评论(0) 推荐(0) 编辑