20170808
来源:互联网 发布:数据安全成熟度模型 编辑:程序博客网 时间:2024/06/07 08:40
///*********************************************************////* STL-Iterator学习 *////*********************************************************///#include <iostream>//#include <list>//#include <vector>//////using namespace std;////int main()//{// // vector<int> v;// for (int i = 1; i <= 9; ++i)// v.push_back(i);// vector<int>::iterator iter = v.begin();//// //随机迭代器 提供“迭代算数运算”// cout << *iter<<endl;// cout << iter[0]<<endl;// iter += 3;// cout << *iter << endl;// iter -= 3;// cout << *iter << endl;//// list<int> coll;// for (int i = 1; i <= 9; ++i)// coll.push_back(i);// list<int>::iterator pos = coll.begin();//// iter_swap(coll.begin(), ++coll.begin());// for (pos; pos != coll.end(); ++pos)// cout << *pos ;// cout << endl;// pos = coll.begin(); //做完循环以后迭代器失效了,需要重新赋值//// iter_swap(coll.begin(), --coll.end());// for (pos; pos != coll.end(); ++pos)// cout << *pos ;// cout << endl;// pos = coll.begin();//// cout << *pos << endl;// advance(pos, 3);// cout << *pos << endl;// advance(pos, -1);// cout << *pos << endl;// // system("pause");//}//#include <iostream> //#include <list> //#include <algorithm> //using namespace std;////int main()//{// list<int> coll;//// //insert elements from -3 to 9 // for (int i = -3; i <= 9; ++i) {// coll.push_back(i);// }//// //search element with value 5 // list<int>::iterator pos;// pos = find(coll.begin(), coll.end(), //range // 5); //value //// if (pos != coll.end()) {// //process and print difference from the beginning // cout << "difference between beginning and 5: "// << distance(coll.begin(), pos) << endl; //8, 第一个位置的distance是0 // }// else {// cout << "5 not found" << endl;// }//}///*********************************************************////* STL-Iterator-iter_swap学习 *////*********************************************************///#include <iostream> //#include <list> //#include <algorithm> //#include <vector>////using namespace std;////int main()//{// list<int> coll;//// //insert elements from 1 to 9 // for (int i = 1; i <= 9; ++i) {// coll.push_back(i);// }//// //swap first and second value // iter_swap(coll.begin(), ++coll.begin());//// //swap first and last value // iter_swap(coll.begin(), --coll.end());//// vector<int> v;// for (int i = 1; i <= 9; ++i) // {// v.push_back(i);// }// //different iterator can swap// iter_swap(find(coll.begin(),coll.end(),3), v.end()-1);//}///*********************************************************////* C++类型转换 *////*********************************************************/#include <iostream>using namespace std;//const_caststruct A{ int a;};//dynamic_castclass AA{public: virtual void foo(){ cout << "i am base foo\n"; };};class BB :public AA{public: void foo(){ cout << "i am derived foo\n"; };};class CC:public AA{};//reinterpret_castint doSomething(){ return 0; };typedef void(*FuncPtr)(); //FuncPtr is 一个指向函数的指针,该函数没有参数,返回值类型为 void int main(){ //const_cast const A ra; const A * pa = new A; //ra.a = 10; 常对象 A& rb = const_cast<A&>(ra); rb.a = 10; A* pb = const_cast<A*>(pa); pb->a = 20; //static_cast int c = 10; double d = static_cast<double>(c); int* p = &c; void *q = static_cast<void*>(p); void* k = NULL; int* s = static_cast<int *>(k); int dd = 9; s = ⅆ //dynamic_cast pc指向子类的指针 AA * pc = new BB(); BB * pc2 = dynamic_cast<BB*>(pc); //子类 - 子类 动态类型转换 pc->foo(); pc2->foo(); //相同基类不同子类的转换 BB* pw = new BB; CC* pw2 = dynamic_cast<CC*>(pw); //pw2为null pw->foo(); //pw2->foo(); 报错 //父类->子类,动态类型转换,安全的!ps2 将是一个NULL 指针。 AA* ps = new AA(); BB* ps2 = dynamic_cast<BB*>(ps); ps->foo(); //ps2->foo(); 报错 //reinterpret_cast FuncPtr funcPtrArray[10]; //10个FuncPtrs指针的数组 让我们假设你希望(因为某些莫名其妙的原因)把一个指向下面函数的指针存入funcPtrArray数组: //funcPtrArray[0] = &doSomething;// 编译错误!类型不匹配,reinterpret_cast可以让编译器以你的方法去看待它们:funcPtrArray funcPtrArray[0] = reinterpret_cast<FuncPtr>(&doSomething); //不同函数指针类型之间进行转换 system("pause");}
阅读全文
0 0
- 20170808
- 20170808
- java学习整理20170808
- SQL语法学习20170808
- 酒客项目日志20170808
- 优化,20170808看视频整理
- 20170808-selenium获取列表内容2
- 20170808面试问题----SQL优化怎么写
- MySQL学习笔记——20170808
- 20170808(工具包中一些常用的方法)
- 20170808(全排列生成函数 list 拓扑排序)
- 20170807-20170808工作记账流水(2017-08-08 10:00)
- Android 控件数组
- Android如何降低service被杀死概率
- 微信网页电话簿-jquery mobile 工具vs2010
- 损失函数改进之Center Loss
- spring事物配置,声明式事务管理和基于@Transactional注解的使用
- 20170808
- Struts2最新版(2.5.12)快速入门(三) Struts2之Annotation
- jzoj 1749 城市交通
- nyoj119 士兵杀敌(三)RMQ算法
- RSA公匙加密算法
- spring实战读书笔记
- cordova 混合开发中苹果iOS开发中直接跳转到App Store里面自己的app的方法
- spring mvc DispatcherServlet详解之前传---前端控制器架构
- 2017.08.08 B组解题报告