I know this is very basic but somehow working on different technologies I have mashed up my C++ concepts
I have created a simple program but it is giving exception when the destructor is called.
Below is the code:
#include "stdafx.h" #include<iostream> using namespace std; class Employee { public: Employee(char *name){ cout<<"Employee::ctor\n"; myName_p = new char(sizeof(strlen(name))); myName_p = name; } void disp(){cout<<myName_p;} ~Employee() { cout<<"Employee:dtor\n\n"; delete myName_p; } private: char *myName_p; }; int main() { Employee emp("check"); emp.disp(); return(0); } Requesting all to clear this basic concept. As per my understanding we can't use delete[] because we are not using new[] in this case. Though I have tried using delete[] , but still it was giving error
std::string"sizeof(strlen(name))is the size of asize_t, not the size of the block of memory needed for the parameter. Consider trying it like this