c++ - Can I use const_cast on a copy of a pointer? -
is there undefined behavior here?
#include <iostream> #include <string> int main() { std::string str = "hello"; auto p = str.c_str(); char x[] = "sup"; const_cast<char*&>(p) = x; }
no, casting away constness of inherently const object , modifying gives ub not otherwise.
Comments
Post a Comment