Can anybody explain me why I need to delete the pointer of object in this?? this was shown in most of the website I was seeking
#include <iostream> #include <string> using namespace std; class Employee { public: Employee(string n, double s, long int i, string p, string c) :name(n), salary(s), id(i), post(p), company(c) {}; void getInfo() { cout << "Name: " << name << endl; cout << "Salary: " << salary << endl; cout << "ID: " << id << endl; cout << "Post: " << post << endl; cout << "Company: " << company << endl; } private: string name; double salary; long int id; string post; string company; }; int main() { Employee *e1 = new Employee("Rocky", 120000000000000000000000.00, 8055, "CEO", "INDIA"); e1->getInfo(); // here //can anybody explain me why i should delete this // it was recommended but why; delete e1; return 0; }