std::string copy constructor NOT deep in GCC 4.1.2?

后端 未结 2 1551
日久生厌
日久生厌 2021-02-19 13:08

I wonder if i misunderstood something: does a copy constructor from std::string not copy its content?

string str1 = \"Hello World\"         


        
2条回答
  •  悲&欢浪女
    2021-02-19 14:05

    It is entirely possible that your string implementation uses copy-on-write which would explain the behavior. Although this is less likely with newer implementations (and non-conforming on C++11 implementations).

    The standard places no restriction on the value of the pointer returned by c_str (besides that it points to a null-terminated c-string), so your code is inherently non-portable.

提交回复
热议问题