cuốn sách gpt4 ai đã làm

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

In lại Tác giả: Walker 123 更新时间:2023-11-28 01:40:53 30 4
mua khóa gpt4 Nike

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

mã số

#include 
#include

// string
using std::string;

// vector
using std::vector;

class Person{
riêng tư:
tên chuỗi;
int tuổi;
công cộng:
Person(string& name, int& age);
};

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

int chính(){
vector 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;

trả về 0;
}

错误

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

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

câu trả lời hay nhất

Bạn cần sử dụng delete[] thay vì delete 来删除数组。

delete[] names;
delete[] ages;

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

30 4 0
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress