2013年3月13日

c++ stl algorithm: std::find, std::find_if

摘要: 原文地址:http://blog.csdn.net/ilysony/article/details/6526545std::find:查找容器元素, find只能查找容器元素为<基本数据类型>#include <iostream>#include <vector>#include <algorithm>int main(){ std::vector<int> v; for (int i = 0; i < 10; ++i) v.push_back(i); std::vector<int>::iterator iter 阅读全文

posted @ 2013-03-13 14:06 zhuyf87 阅读(5662) 评论(0) 推荐(0) 编辑

vc++ warning C4541 'typeid' used on polymorphic type with GR-

摘要: 在vc2008编译器下使用c++ typeid操作符时,提示如下警告,并在运行时崩溃。warning C4541: 'typeid' used on polymorphic type 'XXX' with /GR-; unpredictable behavior may result.在vc++编译器中,“/GR”选项的作用如下:When /GR is on, the compiler defines the _CPPRTTI preprocessor macro./GR- disables run-time type information.Use /GR i 阅读全文

posted @ 2013-03-13 09:45 zhuyf87 阅读(1032) 评论(0) 推荐(0) 编辑

c++ typeid获取类型名

摘要: 在我的项目中,有这样一个需求:在socket(TCP协议)通信部分,需要根据不同的业务协议类型分别设置一个不同的block时间。而此时我已经拿到了指向该协议(数据)对象的(父类型)指针。那最简单的区分不同协议的方式就是使用c++的 typeid操作符。typeid操作符的作用就是获取一个表达式的类型。返回结果是const type_info&。不同编译器实现的type_info class各不相同。但c++标准保证它会实现一个name()方法,该方法返回类型名字的c-style字符串。如果typeid的操作数不是类类型或者是没有虚函数的类,则typeid指出该操作数的静态类型。如果操作 阅读全文

posted @ 2013-03-13 09:23 zhuyf87 阅读(28646) 评论(3) 推荐(1) 编辑

导航