"샘플"에 대한 s 및 s2 내부 포인터가 동일하지 않다는 것에 놀랐습니다. 설명은 무엇입니까?std :: move - std :: string - 내부 포인터
#include <string>
#include <cassert>
int main()
{
std::string s("sample");
std::string s2(std::move(s));
assert(
reinterpret_cast<int*>(const_cast<char*>(s.data())) ==
reinterpret_cast<int*>(const_cast<char*>(s2.data()))
); // assertion failure here
return 1;
}
제쳐두고, 왜 캐스트가 되었습니까? 그들은 아무 것도하지 않습니다. 's.data() == s2.data()'는 동일합니다. –
나는 adresses를 인쇄하여 두 번째로 assert로 전환했기 때문에 ... 쓰기를 간소화하는 것을 잊어 버렸습니다. – Guillaume07