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 ...
随机推荐
- 【转载】Gradle构建多模块项目
本文转载自:https://yq.aliyun.com/articles/25589写的非常好! 改动如下: 1. 增加了一些[补充说明]. 2. 将执行命令使用较为显眼的博客园样式. 3. 将输出结 ...
- centos7 启动httpd的时候为什么显示是这样的
我输入 service httpd start显示一下内容:Redirecting to /bin/systemctl start httpd.service -------------------- ...
- 安装composer slim(php web api micro services)
1. 安装php7 2. 下载 https://getcomposer.org/composer.phar 3. 开启ssh, 在 php.ini中.extension=C:\Program File ...
- [Jobdu] 题目1516:调整数组顺序使奇数位于偶数前面
题目描述: 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的偶数位于位于数组的后半部分,并保证奇数和奇数,偶数和偶数之间的相对位置不变. 输入: 每个输 ...
- iptables清空链的规则
建立iptables时,首先需要情况系统默认的规则(如果有),这样能够保证iptables按照自己的想法运行. iptables -F //清空链规则,但不会情况子链,也不会清空表的默认策略 ip ...
- Xilinx ISE Design Suite 14.7 ISim 简单仿真
1.创建完项目(以Xilinx ISE Design Suite 14.7开发流程的例子 led例子 为例),编译通过,我们就可以对这个项目进行仿真: 2.然后切换到simulation,然 ...
- [na][tools]tcp/udp连通性测试
一 端口连通性测试意义 目的端可以使用nc来临时开一个端口,客户端用telnet来连接测试 测试网络端口可达性,确保给某些使用特定端口的app做链路连通性检测.使它们能够正常的运行起来. 二 测试方法 ...
- Javac编译器
One Compiler http://www.oracle.com/technetwork/java/jvmls2016-wimmer-3125555.pdf Hacking the OpenJDK ...
- Spring 是如何解决并发访问的线程安全性问题的
springmvc的controller是singleton的(非线程安全的),这也许就是他和struts2的区别吧!和Struts一样,Spring的Controller默认是Singleton的, ...
- LeetCode: Word Ladder II 解题报告
Word Ladder II Given two words (start and end), and a dictionary, find all shortest transformation s ...