C++17
#include <stdio.h>
#include <memory>
class OK {
public:
int value;
OK(int x):value(x){
printf("Constructor:%d\n",value);
}
OK(const OK&) = delete;
OK& operator= (const OK&) = delete;
OK(OK&&) = delete;
OK& operator=(OK&&) = delete;
void doit() {
printf("Hello World:%d", value);
}
};
OK Get() {
return OK(5);
}
int main()
{
OK x(3), z(1);
// OK y(x); // No Copy constructor
// OK w(std::move(z)); // No move constructor
// x=Get(); // No assignment. If move is available, it will compile
// x = std::move(z); // No move assignment
OK y=Get();
y.doit(); // RVO without copy, assignment, move, move assignment
return 0;
}
【 在 here080 的大作中提到: 】
: 啥也不用说了,上代码吧
:
--
FROM 98.42.143.*