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

Popular posts from this blog

ios - Memory not freeing up after popping viewcontroller using ARC -

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -