In this post, we will see how to resolve Casting const void* const to const char* const produces the “ignored-qualifiers” warning, why?
Question:
I don’t understand why the following code gives the “type qualifiers ignored on cast result type” warning in GCC, can you please explain?Best Answer:
A non-class non-array prvalue cannot be cv-qualified.This means that your
static_cast<const char* const>(a)
is exactly the same as static_cast<const char*>(a)
, the pointer itself isn’t const-qualified. It’s simply discarded, which is what the warning is telling you about (the second const
is what is being ignored)If you have better answer, please add a comment about this, thank you!
Source: Stackoverflow.com