0

below i wrote a simple example to demonstrate the problem I experience. After executing the code, I get a cygwin exception 7200. I have looked around and tried a few things but to no resolve. Could somebody explain why do I get it, and how could I fix it? Appreciate your time, and many thanks in advance!

Code

#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;
}

Error

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

P.S - I am relatively new to C++.

2
  • How are you executing the code ? Commented Nov 10, 2017 at 20:22
  • I compile g++ -std=c++11 foo.cpp then it makes an executable say - foo.exe. Given the file is available, I just type foo.exe in command-line prompt and get it executed. Commented Nov 10, 2017 at 20:24

1 Answer 1

2

You need to delete arrays with delete[] rather than delete.

delete[] names;
delete[] ages;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.