2021年4月26日

摘要: C++(template模板 && 类模板 碰到有元函数类内实现) 类模板,碰到有元函数类内实现 template<class T1,class T2> class Person { public: Person(T1 name,T2 age):m_Name(name),m_Age(age){} P 阅读全文
posted @ 2021-04-26 11:47 lodger47 阅读(72) 评论(1) 推荐(0)
摘要: C++(template模板 && 类模板 成员函数类外实现) 类模板,成员函数类外实现 #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> using namespace std; template<class 阅读全文
posted @ 2021-04-26 11:32 lodger47 阅读(148) 评论(0) 推荐(0)
摘要: C++(template模板 && 类模板 碰到继承) 类模板,碰到继承 template<class T> class Base { public: T m_A; }; class Child :public Base<int> { }; template<class T1,class T2> c 阅读全文
posted @ 2021-04-26 11:15 lodger47 阅读(143) 评论(0) 推荐(0)
摘要: C++(template模板 && 类模板,做函数参数) 类模板,作为函数参数的几种形式 //1 指定传入类型 void doWork(Person<string, int> &p) { p.show(); } void test03() { Person<string, int> p("MT", 阅读全文
posted @ 2021-04-26 11:09 lodger47 阅读(349) 评论(0) 推荐(0)
摘要: C++(template模板 && 类模板,显示指定类型) 类模板,显示指定类型 #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> using namespace std; template<class Nam 阅读全文
posted @ 2021-04-26 10:41 lodger47 阅读(616) 评论(0) 推荐(0)
摘要: C++(template模板 && 具体化自定义数据类型) 具体化自定义数据类型 class Person { public: Person() {} ~Person() {} Person(int age) :m_Age(age){} int m_Age; }; template<class T> 阅读全文
posted @ 2021-04-26 10:32 lodger47 阅读(391) 评论(0) 推荐(0)
摘要: C++(template模板 && 函数模板) 如果函数模板和普通函数,发成重载会优先调用普通函数,如果没有实现,会出错 区别 普通函数可以进行隐式类型转换,模板不可以 template<class T> void myPrint(T a, T b) { cout << "函数模板" << endl 阅读全文
posted @ 2021-04-26 10:05 lodger47 阅读(109) 评论(0) 推荐(0)

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 阅读(36) 评论(0) 推荐(0)
摘要: c++(虚析构,解决多态时析构函数没有调用子类析构,到时释放不干净) //普通析构 是不会调用子类的析构,所以可能导致释放不干净 //父类的虚析构 virtual ~Animal() { cout<<"Base 析构函数调用了"<<endl; } //纯虚析构,需要实现,类内声明,类外实现 virt 阅读全文
posted @ 2021-04-25 16:13 lodger47 阅读(44) 评论(0) 推荐(0)
摘要: c++(多态 && 计算器案例) 利用多态实现计算器案例,利于后期的扩展,机构性非常好,可读性高 class abstractCalculator{ public: //纯虚函数,如果父类中有了纯虚函数,那么子类在继承中必须继承纯虚函数,这个父类也就无法实例化对象 virtual int getRe 阅读全文
posted @ 2021-04-25 15:34 lodger47 阅读(83) 评论(0) 推荐(0)

导航