2021年4月26日

摘要: C++(自定以异常类) class myException //自定以异常类 { public: void printError() { cout << "自定以异常类" << endl; } }; int myDevide(int a, int b) { if (b == 0) { throw m 阅读全文
posted @ 2021-04-26 16:26 lodger47 阅读(24) 评论(0) 推荐(0) 编辑
摘要: C++(异常) int myDevide(int a, int b) { if (b == 0) { //throw - 1;//抛出int类型异常 throw 3.13; } return a / b; } void test01() { int a = 10; int b = 0; try { 阅读全文
posted @ 2021-04-26 16:12 lodger47 阅读(25) 评论(0) 推荐(0) 编辑
摘要: C++(template模板 && 类模板 碰到有元函数类外实现) 类模板,碰到有元函数类内实现 #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> using namespace std; //让编译器提前看到 阅读全文
posted @ 2021-04-26 13:40 lodger47 阅读(59) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(62) 评论(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 阅读(128) 评论(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 阅读(135) 评论(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 阅读(305) 评论(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 阅读(582) 评论(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 阅读(362) 评论(0) 推荐(0) 编辑
摘要: C++(template模板 && 函数模板) 如果函数模板和普通函数,发成重载会优先调用普通函数,如果没有实现,会出错 区别 普通函数可以进行隐式类型转换,模板不可以 template<class T> void myPrint(T a, T b) { cout << "函数模板" << endl 阅读全文
posted @ 2021-04-26 10:05 lodger47 阅读(95) 评论(0) 推荐(0) 编辑

导航