右值 Test
#include <iostream> #include <vector> #include <mutex> #include <memory.h> using namespace std; int e = 6; int getNum() { return 5; }; int main() { int a = std::move(getNum()); int b = getNum(); const int c = getNum(); //const& int d = getNum(); error 即const& 不能直接返回右值,面试回答错了 //const& int d = std::move(getNum());error 即const& 不能直接返回右值,面试回答错了 //const& int d = std::forward(getNum()); cout <<a<<endl; cout <<b<<endl; cout <<c<<endl; int e = 5; cout <<e<<endl; for(int i = 0; i < 10;i++) { cout <<i<<endl; } int f,k; cout << f <<endl; cout << k <<endl; getchar(); return 0; }