gpt4 book ai didi

C++ | Q : cygwin exception when executing the executable |

转载 作者:行者123 更新时间:2023-11-28 01:40:53 30 4
gpt4 key购买 nike

下面我写了一个简单的例子来演示我遇到的问题。执行代码后,我得到一个 cygwin 异常 7200。我环顾四周并尝试了一些事情,但没有解决。有人可以解释为什么我得到它,我该如何解决?感谢您抽出宝贵时间,在此先致谢!

代码

#include <string>
#include <vector>

// string
using std::string;

// vector
using std::vector;

class Person{
private:
string name;
int age;
public:
Person(string& name, int& age);
};

Person::Person(string& name, int& age): name(name), age(age){}

int main(){
vector<Person> people;

string* names = new string[3];

names[0] = "bob";
names[1] = "alice";
names[2] = "hank";

int* ages = new int[3];

ages[0] = 10;
ages[1] = 20;
ages[2] = 30;

for(unsigned int i = 0; i < 3; ++i){
Person person(names[i], ages[i]);
people.push_back(person);
}

delete names;
delete ages;

return 0;
}

错误

0 [main] a 7200 cygwin_exception::open_stackdumpfile: Dumping stack trace to a.exe.stackdump

P.S - 我对 C++ 比较陌生。

最佳答案

您需要使用 delete[] 而不是 delete 来删除数组。

delete[] names;
delete[] ages;

关于C++ | Q : cygwin exception when executing the executable |,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47230511/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com