+ 1

core dumped in c++

Hello. Im trying to create an object wich it is from class Person and if i create only one object with persons[0].setName("John"); , i dont have any error, but if i insert another person object with persons[1].setName("Tanjil"); i have like "timeout core dumped error". I would like to know why this happens and how to fix it? Appreciate any response. Thats the program https://code.sololearn.com/clbMH24ZJd40/?ref=app

1st Sep 2020, 10:56 AM
Tanjil Khan
Tanjil Khan - avatar
2 ответов
+ 2
The problem lies in `setName` function. You have not yet allocated memory for member <name> and you try to copy <name> argument over to member <name>. Personally I'd prefer std::string instead to avoid this kind of problem
1st Sep 2020, 11:16 AM
Ipang