I would like to understand why can't we get const volatile reference to rvalue reference? I mean what is the rational reason to prohibit such a conversion?
In the following code I comment out lines that do not compile:
int main(){
int i=1;
volatile int& vi=i;//no trouble
const int& ci=i;//no trouble
const volatile int& cvi=i;//no trouble
//int& i2 = std::move(i); -> ERROR:make sens, better not changing an object referred to
// by an rvalue reference. The referred object could be
// in an invalid state.
//volatile int& vi2=std::move(i); -> ERROR:make sens, for the same previous reason.
const int& ci2=std::move(i);//No error: whatsoever the object won't be changed, and it
// it is needed for expression like f(g()) to compile;
//const volatile int& cvi2=std::move(i); -> ERROR: why?
const volatile int i2=0;
//const volatile int& cvi3=std::move(i2);// -> ERROR: why?
}
Aucun commentaire:
Enregistrer un commentaire