随笔分类 -  C++

上一页 1 2 3 4 5 6 ··· 8 下一页
摘要:1 #include 2 //用于字符串的输入输出 3 #include 4 #include 5 #include 6 //用于输出到字符串 7 #include 8 using namespace std; 9 10 void main1() 11 { 12 //创建字符串流(sprintf) 13 stringstream my... 阅读全文
posted @ 2018-03-21 23:12 喵小喵~ 阅读(264) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 //get 三个参数版本(读取一个,读取指定长度,读取到指定字符终止) 8 //getline 2个版本 9 //lcin.ignore(numeric_limits::max(),'#'); 忽略指定字符前的元素 10 //c... 阅读全文
posted @ 2018-03-21 22:37 喵小喵~ 阅读(143) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 void main() 8 { 9 10 /*char ch1, ch2, ch3; 11 cin.get(ch1).get(ch2).get(ch3); 12 cout.put(ch1).put(ch... 阅读全文
posted @ 2018-03-21 22:17 喵小喵~ 阅读(114) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 using namespace std; 4 5 void main() 6 { 7 ////调用cout的成员函数输出到屏幕 8 //cout.put('a').put('b').put('c'); 9 //char str[100] = "hello world"; 10 //// ... 阅读全文
posted @ 2018-03-21 22:03 喵小喵~ 阅读(120) 评论(0) 推荐(0)
摘要:1 #include 2 using namespace std; 3 4 //静态函数没有this指针,无需创建对象就可以直接调用 5 6 template 7 class myclass 8 { 9 public: 10 void go1() 11 { 12 13 } 14 static void go2() 15 { 16 ... 阅读全文
posted @ 2018-03-21 17:59 喵小喵~ 阅读(254) 评论(0) 推荐(0)
摘要:1 #include 2 using namespace std; 3 4 //static成员,每个类型都会实例化,创建一个变量,类型一致则共享,否则不共享 5 6 template 7 class myclass 8 { 9 public: 10 static int num; 11 myclass() 12 { 13 num... 阅读全文
posted @ 2018-03-21 17:55 喵小喵~ 阅读(541) 评论(0) 推荐(0)
摘要:1 #include 2 using namespace std; 3 4 //模板类的声明,可以引用友元类,也可以创建引用或者指针,不能创建全局对象 5 templateclass showit; 6 7 //错误 8 //showit myint; 9 10 //模板类 11 template 12 class myclass 13 { 14 public: 15... 阅读全文
posted @ 2018-03-21 17:48 喵小喵~ 阅读(116) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 template 8 class men 9 { 10 public: 11 men() 12 { 13 14 } 15 ~men() 16 { 17 18 } 19 2... 阅读全文
posted @ 2018-03-21 17:34 喵小喵~ 阅读(116) 评论(0) 推荐(0)
摘要:1 #include 2 using namespace std; 3 4 //类模板不调用不编译 5 template 6 class myclass 7 { 8 public: 9 T a; 10 T b; 11 T add() 12 { 13 return a + b; 14 } 15 }; 16 17 voi... 阅读全文
posted @ 2018-03-21 17:10 喵小喵~ 阅读(160) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 using namespace std; 4 5 //函数包装器,左边参数右边函数 6 template 7 T run(T t, F f) 8 { 9 return f(t); 10 } 11 12 //先获取类型再执行操作 13 template 14 T runit(T t) 15 { 16 //获取... 阅读全文
posted @ 2018-03-21 00:01 喵小喵~ 阅读(152) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 template 7 class myarray 8 { 9 private: 10 T * p; 11 public: 12 myarray(initializer_list mylist) 13 { 14 ... 阅读全文
posted @ 2018-03-20 23:40 喵小喵~ 阅读(119) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 using namespace std; 4 5 //类模板支撑封装 继承 还有多态 6 template 7 class Tfu 8 { 9 public: 10 T t; 11 Tfu():t(0) 12 { 13 14 } 15 void show() 16 { 17 ... 阅读全文
posted @ 2018-03-20 23:25 喵小喵~ 阅读(107) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 using namespace std; 4 5 //模板不能用virtual 6 //函数模板与类成员可以互相调用 7 8 class myclass 9 { 10 template 11 T add(T a) 12 { 13 return a; 14 } 15 t... 阅读全文
posted @ 2018-03-20 21:29 喵小喵~ 阅读(133) 评论(0) 推荐(0)
摘要:1 #include 2 using namespace std; 3 4 class myclass 5 { 6 public: 7 //函数模板,不调用不编译 8 template 9 T add(T a, T b) 10 { 11 return a + b; 12 } 13 14 template ... 阅读全文
posted @ 2018-03-20 21:23 喵小喵~ 阅读(84) 评论(0) 推荐(0)
摘要:1 #include 2 using namespace std; 3 4 //子类同名函数覆盖父类 5 //父类指针存储子类地址,在有虚函数情况会调用子类方法,否则会调用父类方法 6 7 class base 8 { 9 public: 10 virtual void show() 11 { 12 cout show(); 29 ... 阅读全文
posted @ 2018-03-20 21:13 喵小喵~ 阅读(190) 评论(0) 推荐(0)
摘要:1 #include 2 using namespace std; 3 4 //多态调用依赖指针或者引用 5 //对象调用会调用拷贝构造,拷贝一个父类,无法实现多态 6 //如果要使用别继承的虚函数,不允许出现虚函数的重载 7 //多态可以跨类,爷爷辈的指针可以存储孙子辈的地址 8 9 class myclass 10 { 11 public: 12 virtua... 阅读全文
posted @ 2018-03-20 20:57 喵小喵~ 阅读(108) 评论(0) 推荐(0)
摘要:1 #include 2 using namespace std; 3 4 class myclass 5 { 6 public: 7 //后面加一个final,则禁止虚函数被子类重写 8 //final必须对应虚函数 9 virtual void run() final 10 { 11 12 } 13 14 virtua... 阅读全文
posted @ 2018-03-20 20:22 喵小喵~ 阅读(100) 评论(0) 推荐(0)
摘要:1 #include 2 using namespace std; 3 4 class myclass 5 { 6 public: 7 virtual void go() 8 { 9 cout go(); 56 birdpeople aa; 57 cin.get(); 58 } 阅读全文
posted @ 2018-03-20 20:14 喵小喵~ 阅读(118) 评论(0) 推荐(0)
摘要:1 #include 2 using namespace std; 3 4 //构造函数不可以是虚函数,如果是虚函数子类对象中的父类拷贝无法初始化 5 //继承的本质就是子类中间包含父类对象 6 //析构是从子类析构然后父类析构,如果是多态并且子类中有分配内存, 7 //父类对象用子类初始化,则需要把析构函数设成virtual 8 9 class myclass 10 {... 阅读全文
posted @ 2018-03-19 21:17 喵小喵~ 阅读(121) 评论(0) 推荐(0)
摘要:1 //#include 2 //using namespace std; 3 // 4 // 5 //void main() 6 //{ 7 // cin.get(); 8 //} 9 10 #define _CRT_SECURE_NO_WARNINGS 11 #include 12 using namespace std; 13 14 class father... 阅读全文
posted @ 2018-03-19 20:41 喵小喵~ 阅读(177) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 ··· 8 下一页