e.doroskevic
e.doroskevic

Reputation: 2169

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

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++.

Upvotes: 0

Views: 95

Answers (1)

harmic
harmic

Reputation: 30577

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

delete[] names;
delete[] ages;

Upvotes: 2

Related Questions