1
#include <iostream>
#include <string>
#include <vector>
class X
{
public:
int& a;
int&& b;
X(int& c, int && d):a(c), b(std::move(d))
{
}
};
X* x = nullptr;
void fun()
{
std::cout<<"Fun\n";
int l = 8;
int r = 9;
std::cout << &(l) << std::endl;
std::cout << &(r) << std::endl;
x = new X(l, std::move(r));
}
int main()
{
fun();
std::cout << x->a << std::endl;
std::cout << &(x->a) << std::endl;
std::cout << x->b << std::endl;
std::cout << &(x->b) << std::endl;
}
=> 회원 변수 참조 값 (lvalue
및 rvalue
)은 쓰레기가됩니까?
다른 컴파일러에서 다른 동작이 나타납니다. 그래서 C++ 표준이 이것에 대해 뭐라고하는지 알고 싶었습니다.클래스의 멤버 변수로 Rvalue 및 Lvalue 참조 - 유효합니까?
'rvalue' * 참조 * 데이터 멤버로 * 잘 끝내지 않을 것입니다 .... BTW, 당신은 [전체 타입을 실제로 움직일 수 없습니다.] (https://stackoverflow.com/questions/14679605/do-built-types-have-move-semantics) .. – WhiZTiM