#include <iostream>
#include <string>
class MyClass
{
public:
virtual void fun1() = 0;
private:
};
class A : public MyClass {
public:
A() {}
~A() {}
};
void fun(const std::string& str) {
std::cout << "std::move不会转移str参数" << str;
}
void fun2(std::string str) {
std::cout << "std::move会转移str参数" << str;
}
int main()
{
//A继承纯虚类MyClass 继承不用是可以编译过的
//声明变量A a; 编译报错
std::string test1("11");
fun(std::move(test1));
//test1="11"不为空
std::string test2("11");
fun2(std::move(test2));
//test2 = "" 为空
std::move(test1); //不为空 ,不转移所有权 warning C4834: 放弃具有 "nodiscard" 属性的函数的返回值
//test1 = "11"
std::string mm = std::move(test1);//转移所有权
//test1 = ""
//lambda表达式
std::string mm1;
auto ld = [&]() ->void {
mm1 = "11"; //ok
};
auto ld02 = []() ->void {
//mm1 = "11"; // erro 报错 error C3493: 无法隐式捕获“mm1”,因为尚未指定默认捕获模式
};
}
//char data[16] = { "hello world 123" };
// 123 world hello