My codes are as below:
<code>#include <string>
#include <iostream>
using namespace std;
int main()
{
string s1 = "hello";
string s2 = move(s1);
std::cout << "s1:" << s1 << std::endl;
std::cout << "s2:" << s2 << std::endl;
return 0;
}
</code>
<code>#include <string>
#include <iostream>
using namespace std;
int main()
{
string s1 = "hello";
string s2 = move(s1);
std::cout << "s1:" << s1 << std::endl;
std::cout << "s2:" << s2 << std::endl;
return 0;
}
</code>
#include <string>
#include <iostream>
using namespace std;
int main()
{
string s1 = "hello";
string s2 = move(s1);
std::cout << "s1:" << s1 << std::endl;
std::cout << "s2:" << s2 << std::endl;
return 0;
}
I know move
can be seen as a typical implementation
<code>template <typename T>
typename remove_reference<T>::type&& move(T&& arg)
{
return static_cast<typename remove_reference<T>::type&&>(arg);
}
</code>
<code>template <typename T>
typename remove_reference<T>::type&& move(T&& arg)
{
return static_cast<typename remove_reference<T>::type&&>(arg);
}
</code>
template <typename T>
typename remove_reference<T>::type&& move(T&& arg)
{
return static_cast<typename remove_reference<T>::type&&>(arg);
}
My question is why s1
is null while s2
is hello
, and under what circumstances can an object still be used normally after calling move
on it?
1