I had to change the prototype of a function getData() which is basically a legacy source code. Upon changing it from returning a char* as shown below, I started getting compile errors due to static_cast.The question I have is , Is it safe to use reinterpret_cast, instead of static_cast?
class C1{
public:
//void *getData() {return data;} //Legacy implementation*
char *getData() {return data;} //My new implementation
private:
char data[100];
};
int main()
{
C1 myobj;
unsigned char* begin;
begin=static_cast<unsigned char*>(myobj.getData()); *//<== This gives compile error.use reinterpret_cast ?*
return 0;
}
Is there a better solution than reinterpret_cast ?