对象的移动
int main()
{
String s1("One"), s2("Two");
cout << s1 << " " << s2 << endl << endl;
String s3(s2);
cout << s1 << " " << s2 << " " << s3 << " " << endl << endl;
s3 = s2;
cout << s1 << " " << s2 << " " << s3 << " " << endl << endl;
s3 = String("Three");
std::vector<String> vs;
cout << "kaishi cheshi " << endl;
vs.push_back(s1);
cout << "push_back number 2 " << endl;
vs.push_back(std::move(s2));
cout << "push_back number 3" << endl;
vs.push_back(String("Three"));
cout << "push_back number4" << endl;
vs.push_back("Four");
for_each(vs.begin(), vs.end(), [](String &s) {cout << s << endl; });
system("pause");
return 0;
}
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于