vector push_back报错
场景:定义了一个结构体,包含一个vector的成员变量,在给这个vTQ push_back数据的时候报错。
typedef struct tag_TQInfo
{
int iTime;
int iMarket;
string sCode;
vector<string> vTQ; tag_TQInfo()
{
memset(this, 0, sizeof(tag_TQInfo));
}
}TQINFO,*LPTQINFO;
原因:
tag_TQInfo构造函数用了memset,将分给tag_TQInfo的那块内存都初始化了,也就把vector vTQ自带的东西都清零了,破坏了vector的结构,会导致之后vTQ使用出错。
vector定义变量时会自己完成初始化工作。
解决方法:
当结构体中包含vector、string等复杂数据类型,或包含自定义的结构时,构造函数初始化时不能使用memset。
typedef struct tag_TQInfo
{
int iTime;
int iMarket;
string sCode;
vector<string> vTQ; tag_TQInfo()
: iTime(0)
, iMarket(0)
{ }
}TQINFO,*LPTQINFO;
vector push_back报错的更多相关文章
- std::vector push_back报错Access violation
C/C++ code ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 #include < ...
- vs.Debug.vector迭代器报错(_ITERATOR_DEBUG_LEVEL)
1.vs2017.Win7x64 std::vector<ULONG>,在 使用 *iter 取某个 ULONG时 报错,release不报错,报错信息: ZC:具体原理不明,暂时的解决方 ...
- c++ 模板参数做容器参数迭代器报错 vector<T>::const_iterator,typename const报错
错误1: template<class T>void temp(std::vector<T>& container){ std::vector<T& ...
- cocos2d-x 头文件中添加方法变量导致编译报错
代码如下: HelloWorldScene.h #ifndef __HELLOWORLD_SCENE_H__#define __HELLOWORLD_SCENE_H__ #include " ...
- caffe ubuntu16安装报错和程序总结
我最近安装安装了老版本的caffe,安装过程真是两个字"想死",所以我的错误一般都是比较经典的. 我是使用cuda的版本,所以可能会出现undefined refference t ...
- 又一种Mysql报错注入
from:https://rdot.org/forum/showthread.php?t=3167 原文是俄文,所以只能大概的翻译一下 这个报错注入主要基于Mysql的数据类型溢出(不适用于老版本的M ...
- boost pool_allocator 报错 'rebind'
#include "stdafx.h" #include <vector> #include <boost/pool/pool.hpp> int _tmai ...
- 报错解决——Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
在导入tensorflow后,进行运算时,出现了报错Your CPU supports instructions that this TensorFlow binary was not compile ...
- 加载rocksdb实例报错:java.lang.UnsatisfiedLinkError: C:\Users\Administrator\AppData\Local\Temp\librocksdbjni3696928169151614297.dll
项目的缓存中用到了rocksdb,实例化时报错了: Related cause: org.springframework.beans.factory.BeanCreationException: Er ...
随机推荐
- 使用xshell远程登录ubuntu使用vi编辑不能使用删除键方向键
近期安装了xshell,远程登录上ubuntu后,在插入模式下,按删除键没有任何反应,按方向键分别打印出A.B.C.D,每个字符一行. 这是因为ubuntu初始化安装的是vi的tiny版本,解决办法安 ...
- 深入理解Docker Volume(一)
想要了解Docker Volume,首先我们需要知道Docker的文件系统是如何工作的.Docker镜像是由多个文件系统(只读层)叠加而成.当我们启动一个容器的时候,Docker会加载镜像层并在其上添 ...
- 几种常见排序算法之Java实现(插入排序、希尔排序、冒泡排序、快速排序、选择排序、归并排序)
排序(Sorting) 是计算机程序设计中的一种重要操作,它的功能是将一个数据元素(或记录)的任意序列,重新排列成一个关键字有序的序列. 稳定度(稳定性)一个排序算法是稳定的,就是当有两个相等记录的关 ...
- vim设置文本宽度
'textwidth' 'tw' number (default 0) local to buffer ...
- JS教程:window.location使用方法的区别
介绍了window.location使用方法的区别. window.location.href=&http://www.jbxue.com/javascript/ldquo;url”:改变ur ...
- [k8s]kube-router替代kube-proxy实现svc网络和pod网络
本文讲解了kube-router部署,无需在部署kube-proxy了. kube-router采用lvs实现svc网络,采用bgp实现pod网络. kube-router也是基于cni网络,本文是容 ...
- [k8s]kubespray(ansible)自动化安装k8s集群
kubespray(ansible)自动化安装k8s集群 https://github.com/kubernetes-incubator/kubespray https://kubernetes.io ...
- [na]出口选路pbr小实验视频
什么是策略路由? 一般都是部署在出口路由器,用于路径强制分发的, 优先级高于路由表. 策略路由小实验视频 这个是读书时候录的一个策略路由小实验
- Oracle PLSQL Demo - 16.弱类型REF游标[没有指定查询类型,已指定返回类型]
declare Type ref_cur_variable IS REF cursor; cur_variable ref_cur_variable; rec_emp scott.emp%RowTyp ...
- solr中时区处理
solr.in.sh中的最后 # By default the start script uses UTC; override the timezone if needed SOLR_TIMEZONE ...