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 <vector>
#include <string>
#include <iostream>
 
struct Person
{
    std::string name;
    int age;
    std::string bank_ac_no;
 
    Person(const std::string& name, int years,
        const std::string& ac_no) :
        name(name), age(years), bank_ac_no(ac_no) {}
 
    Person() : name(""), age(0), bank_ac_no(""){}
 
};
 
int main(int argc, char *argv[])
{
    struct Person p1 = { "A Smith", 71, "5702750" };
 
    std::vector<Person> people1(0);
    people1.push_back(p1);
     
    return 0;
}

运行的时候在push_back那一句报如下的错误: 
Unhandled exception at 0x50C031CA (msvcr120d.dll) in Test15.exe: 0xC0000005: Access violation reading location 0x391F9350.

试了一下,如果不是push_back自定义的struct,而是push_back一个内置类型(比如int,string)就不会报错.

到底是怎么回事那? 请指教. 谢谢

[问题补充] 新建了一个项目, 把上面的代码拷贝过去,就没有问题. 检查了一下新项目和现在的项目,配置是一模一样的.

[答案]

原来我项目中的其他文件中也定义了一个struct Person, 把其他的一个struct改一下名字就好了.

std::vector push_back报错Access violation的更多相关文章

  1. cout显示Mat类对象报错Access Violation

    AV(Access Violation)错误:非法访问. image_match.exe 中的 0x0000002a 处有未经处理的异常: 0xC0000005: Access violation 程 ...

  2. vector push_back报错

    场景:定义了一个结构体,包含一个vector的成员变量,在给这个vTQ push_back数据的时候报错. typedef struct tag_TQInfo { int iTime; int iMa ...

  3. 网站报错Access denied for user 'root'@'localhost' -问题排查续

    网站报错Access denied for user 'root'@'localhost' (using password: YES) 每次的挽救办法就是: /etc/init.d/mysqld st ...

  4. 报错: Access restriction: The type JPEGImageEncoder is not accessible due to restriction on required library

    报错: Access restriction:The type JPEGCodec is not accessible due to restriction on required library C ...

  5. 008-MySQL报错-Access denied for user 'root'@'localhost' (using password: NO)

    1.新安装的mysql报错 MySQL报错-Access denied for user 'root'@'localhost' (using password: NO) 解决方案 1.先停掉原来的服务 ...

  6. vs.Debug.vector迭代器报错(_ITERATOR_DEBUG_LEVEL)

    1.vs2017.Win7x64 std::vector<ULONG>,在 使用 *iter 取某个 ULONG时 报错,release不报错,报错信息: ZC:具体原理不明,暂时的解决方 ...

  7. PL/SQL插入数据报错:Access violation at address 00413A81 in module 'plsqldev.exe'. Read of address 00000000

    前言 今天同事在使用plsql给oracl数据库插入记录时报错:Access violation at address 00413A81 in module 'plsqldev.exe'. Read ...

  8. MySQL登录报错"Access denied for user 'root'@'localhost' (using password: YES)"

    最近登录MySQL时候总报错: # mysql -uroot -p Enter password: ERROR (): Access denied for user 'root'@'localhost ...

  9. 接口调用 读取图片报错 Access to the path '' is denied.解决方案

    调用接口 读取服务器上 图片 报错: Server was unable to process request. ---> Access to the path '图片路径' is denied ...

随机推荐

  1. Ubuntu18.04上安装Docker-Compose

    1.进入https://github.com/docker/compose/releases 查看最新版本,当前版本为1.23.1 sudo curl -L https://github.com/do ...

  2. 记Ubuntu Mongodb 和 Mysql的安装与使用

    安装mongodb 参考链接 https://www.cnblogs.com/shileima/p/7823434.html https://blog.csdn.net/xlengji/article ...

  3. rem+media+jquery布局结局方案

    ; ; } ? ; + 'px'; } document.addEventListener('DOMContentLoaded', callback); window.addEventListener ...

  4. 004.Ansible Ad-Hoc命令集

    一 Ad-Hoc使用场景 Ad-Hoc更倾向于解决简单.临时性任务. 1.1 Ad-Hoc基础命令 基本语法: 1 ansible <host-pattern> [options] < ...

  5. Python 合并两个列表的多种方式,合并两个字典的多种方式

    一.合并列表 1.最简单的,使用+连接符: >>> a = [1,2,3] >>> b = [7,8,9] >>> a + b [1, 2, 3, ...

  6. python & MySQLdb(two)

    实现python封装 # encoding=utf8 import MySQLdb #定义类 class MysqlHelper(): def __init__(self,host,port,db,u ...

  7. JAVAScript:前端模块化开发

    目录 一:前端模块化概要 1.1.模块化概要 1.2.函数封装 1.3.对象封装 1.4.立即执行函数表达式(IIFE) 1.5.模块化规范 1.5.1.CommonJS 1.5.2.AMD((Asy ...

  8. Unity容器的简单AOP与DI的应用Demo(基于asp.net mvc框架)

    转发请注明出处:https://home.cnblogs.com/u/zhiyong-ITNote/ 整个Demo是基于Controller-Service-Repository架构设计的,每一层之间 ...

  9. Linux下MySQL数据库常用基本操作

    1.显示数据库 show databases; 2.选择数据库 use 数据库名; 3.显示数据库中的表 show tables; 4.显示数据表的结构 describe 表名; 5.显示表中记录 S ...

  10. 狄克斯特拉算法(Python实现)

    概述 狄克斯特拉算法--用于在加权图中找到最短路径 ps: 广度优先搜索--用于解决非加权图的最短路径问题 存在负权边时--贝尔曼-福德算法 下面是来自维基百科的权威解释. 戴克斯特拉算法(英语:Di ...