Whenever I try this code to catch class type as exception I get an error message as "deprecated conversion from string constant to 'char*'" .
Why is it so and how can it be avoided?
#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;
class Error
{
int err_code;
char *err_desc;
public:
Error(int c , char* p)
{
err_code=c;
err_desc=new char(strlen(p));
strcpy(err_desc,p);
}
void display(void)
{
cout<<err_code<<"done successfully"<<err_desc;
}
};
int main()
{
int x;
try
{
cout<<"\n press any key to avoid exception except 99";
cin>>x;
if(x=99)
throw Error(x,"Exception");
}
catch (Error e )
{
cout<<"\n exception caught successfully";
e.display();
}
return 0;
}