2014-09-05 69 views

回答

2

std::string将始终复制从阵列由char *指向。你也可以在一些构造函数中提供一个迭代器范围。

在一个std::string副本中复制或引用计数取决于您正在使用的C++库。

C++ 2011标准要求std :: string制作真正的副本。 2003年的标准允许引用计数副本。

GNU libstdC++使用引用计数的字符串。而为了向后兼容,即使是2011年标准的GCC也可以与它们一起构建。否则,它无法链接到使用2003标准构建的代码。

有一个预处理器定义来启用新行为。

又见std::string copy constructor NOT deep in GCC 4.1.2?Is std::string refcounted in GCC 4.x/C++11?

+2

参考复制字符串时,计数可能发生。但是这个问题是关于复制一个'const char *',它不能被引用计数。 – interjay 2014-09-05 18:52:08

+1

@interjay:也提到operator = though。 – 2014-09-05 18:52:53

+2

它用'const char *'参数提到'operator ='。 – interjay 2014-09-05 18:54:36

相关问题