2021年4月25日

摘要: c++(函数模版) template<class/typename T> 告诉编译器竟跟的代码里面出现的T不要报错 void test(T &a,T &b){} test(10,20);自动类型推导 test<int>(10,20);指定类型推导 阅读全文
posted @ 2021-04-25 23:55 lodger47 阅读(27) 评论(0) 推荐(0) 编辑
摘要: c++(虚析构,解决多态时析构函数没有调用子类析构,到时释放不干净) //普通析构 是不会调用子类的析构,所以可能导致释放不干净 //父类的虚析构 virtual ~Animal() { cout<<"Base 析构函数调用了"<<endl; } //纯虚析构,需要实现,类内声明,类外实现 virt 阅读全文
posted @ 2021-04-25 16:13 lodger47 阅读(37) 评论(0) 推荐(0) 编辑
摘要: c++(多态 && 计算器案例) 利用多态实现计算器案例,利于后期的扩展,机构性非常好,可读性高 class abstractCalculator{ public: //纯虚函数,如果父类中有了纯虚函数,那么子类在继承中必须继承纯虚函数,这个父类也就无法实例化对象 virtual int getRe 阅读全文
posted @ 2021-04-25 15:34 lodger47 阅读(72) 评论(0) 推荐(0) 编辑
摘要: c++(多态) 父类的引用或者指针,指向子类对象 #include <iostream> using namespace std; class Animal{ public: //动态连遍,在父类声明函数上,变成虚函数,发生了多态 virtual void speak() { cout<<"动物在说 阅读全文
posted @ 2021-04-25 10:34 lodger47 阅读(30) 评论(0) 推荐(0) 编辑
摘要: 桶排序 例:算出随机10个数%42余数不同的有几个? #include <iostream> #include <cstring> bool a[42]; //桶 int main() { int count=0,tmp; memset(a,0,sizeof(a)); for(int i=0;i<1 阅读全文
posted @ 2021-04-25 01:00 lodger47 阅读(19) 评论(0) 推荐(0) 编辑

2021年4月24日

摘要: c++(继承 &&菱形继承) #define _CRT_SECURE_NO_WARNINGS #include <iostream> using namespace std; class Animal { public: int m_Age; }; class Sheep :virtual publ 阅读全文
posted @ 2021-04-24 17:01 lodger47 阅读(31) 评论(0) 推荐(0) 编辑
摘要: c++(运算符重载 &&()右移运算符重载) istream& operator>>(istream& cin, MyString& str) { //先清空原有内容 if (str.pString != NULL) { delete[] str.pString; str.pString = NUL 阅读全文
posted @ 2021-04-24 11:09 lodger47 阅读(259) 评论(0) 推荐(0) 编辑
摘要: c++(运算符重载 &&()重载 //()重载 class MyPrint { public: void operator()() { cout << "hello world" << endl; } }; void test01() { MyPrint myPrint; myPrint(); // 阅读全文
posted @ 2021-04-24 10:32 lodger47 阅读(131) 评论(0) 推荐(0) 编辑

2021年4月23日

摘要: c++ (运算符重载 && []运算符重载) []运算符重载,返回数组索引的引用 int& MyArray::operator[](int index) { return this->pAddress[index]; } 阅读全文
posted @ 2021-04-23 17:53 lodger47 阅读(89) 评论(0) 推荐(0) 编辑
摘要: c++ (运算符重载 && 智能指针) class Person { public: Person(){} Person(int age):m_Age(age){} void showAge() { cout << "年龄为: " << this->m_Age; } int m_Age; ~Pers 阅读全文
posted @ 2021-04-23 17:05 lodger47 阅读(98) 评论(0) 推荐(0) 编辑

导航