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)就不会报错.
究竟是怎么回事那? 请指教. 谢谢ios
[问题补充] 新建了一个项目, 把上面的代码拷贝过去,就没有问题. 检查了一下新项目和如今的项目,配置是如出一辙的.spa
[答案].net
原来我项目中的其余文件中也定义了一个struct Person, 把其余的一个struct改一下名字就行了. code