Std::vector Push_back Error Access violation

Source: Internet
Author: User

C + + code?
123456789101112131415161718192021222324252627 #include <vector>#include <string>#include <iostream>structPerson{    std::string name;    intage;    std::string bank_ac_no;    Person(conststd::string& name, intyears,        conststd::string& ac_no) :        name(name), age(years), bank_ac_no(ac_no) {}    Person() : name(""), age(0), bank_ac_no(""){}};intmain(intargc, char *argv[]){    structPerson p1 = { "A Smith", 71, "5702750"};    std::vector<Person> people1(0);    people1.push_back(p1);        return0;}




Run at the time in the push_back that a quote like the following error:
Unhandled exception at 0X50C031CA (Msvcr120d.dll) in test15.exe:0xc0000005:access violation reading location 0x391f9350.

Try, if not push_back custom struct, but push_back a built-in type (such as int,string) will not error.

What the hell is going on? Please advise. Thank you

[Problem added] A new project has been created to copy the above code, so there is no problem. Check the new project and the current project, the configuration is identical.

Answer

It turns out that the other files in my project also define a struct person, and it's good to change the other struct's name.

Std::vector Push_back Error Access violation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.