Possible Duplicate:
behaviour of const_cast
I need to understand what this line means
char A = strdup(const_cast<char*>(aString.c_str()));
I understand what strdup does from this:
strdup() – what does it do in C?
strdup expects a const char pointer. Its the <,> part of the above line that confuses me.
const_cast< type >is a C++ operator. You can read about it here.I don’t understand why it’s needed here, since (assuming
aStringis of typestd::string)c_str()already returns theconst char*whichstrduprequires, and in any case addingconstness is done implicitly.Only if the function receives a non-
constparameter it’s required, and even then it’s usually not recommended.