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

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -