std::vector push_back報錯Access violation

來源:互聯網
上載者:User

標籤:類型   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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.