C++ program get terminated -
i need know why program terminated when ever compile it. cant understand reasons behind termination. please tell me problem solutions. thanks.
#include<iostream.h> class citizen{ private: char* name; char* nationality; public: citizen(){ name = "no name given"; nationality = "no nationality given\n"; } citizen(char* name, char* nationality){ this->name = name; this->nationality = nationality; } void display(){ cout << "name: " << name << endl; cout << "nationality: " << nationality << endl; } ~citizen(){ if(name){ cout << endl << "\ngoing delete: "<< name << endl; delete []name; } if(nationality){ delete []nationality; cout << "going nationality: "<< nationality << endl; } } citizen(const citizen &obj){ int size = sizeof(obj.name); name = new char[size+1]; strcpy(name, obj.name); int size2 = sizeof(obj.nationality); nationality = new char[size2 + 1]; strcpy(nationality, obj.nationality); cout << "\ni'm copy construcotr\n"; } };
the reason termination first line, should be
#include <iostream>
(note: no .h
). old header iostream.h
deprecated (actually never officially part of c++).
some more error pop up, using char*
instead of const char*
, ask when need fix them.
Comments
Post a Comment