文章分类 -  c++基础bufen

摘要:c++语言级别的类型转换 const_cast:去掉常量属性的一个类型转换 static_cast:提供比编译器认为安全的类型转换 reinterpret_cast:提供C风格的强制类型转换 dynamic_cast:主要在继承结构中,可以支持RTTI类型识别的上下类型转换 const_cast i 阅读全文
posted @ 2022-10-21 17:21 satellite2002 阅读(34) 评论(0) 推荐(0) 编辑
摘要:多种继承那些事 理解虚基类和虚继承 抽象类:有虚函数的类 虚基类:被虚继承的类就称作虚基类 虚继承中派生类发生的内存变化 虚继承与多态相结合 class A { public: virtual void func(){cout<<"Base::func"<<endl;} private: int m 阅读全文
posted @ 2022-10-21 17:18 satellite2002 阅读(24) 评论(0) 推荐(0) 编辑
摘要:继承和多态 继承的基本意义: 继承的内存结构: class A { int a; int b; int c; }; class B:public A { int d; int e; int f; }; int main() { //std::cout << "Hello, World!" << st 阅读全文
posted @ 2022-10-18 20:20 satellite2002 阅读(32) 评论(0) 推荐(1) 编辑
摘要:运算符重载 运算符重载的好处:使运算符的表现和编译器内置类型一样 复数类的实现: class CComplex { public: CComplex(int r=0,int m=0) :mimage_(m),mreal_(r) { cout<<"CComplex(int r=0,int m=0)"< 阅读全文
posted @ 2022-10-18 20:19 satellite2002 阅读(37) 评论(0) 推荐(0) 编辑
摘要:模板: 模板的意义:对类型进行参数化 函数模板 template<typename T> bool compare(T a,T b) { cout<<"Template compare"<<endl; return a>b; } int main() { compare<int>(10,20); / 阅读全文
posted @ 2022-10-18 20:18 satellite2002 阅读(25) 评论(0) 推荐(0) 编辑
摘要:形参带参数的默认函数 int sum(int a=10,int b=20) { return a+b; } int main() { int a = 10;int b = 20; int ret = sum(a,b); /*mov eax,dword ptr[ebp-8] *push eax *mo 阅读全文
posted @ 2022-10-18 20:14 satellite2002 阅读(355) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示