標籤:類型 csdn syn 怎麼 ESS sso ref exe title
C/C++ code ?
| 123456789101112131415161718192021222324252627 |
#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