K
kyle
Consider following code:
int main() {
const int& c = int();
int& m = const_cast<int&>(c);
m = 4;
}
The object of the snippet is to get a mutable reference to a temporary.
This cant be done directly because non-const reference cannot bind to
temporary, but we should be OK with casting away constness of reference
'c' since it doesn't actually refer to const object.
Temporaries are mutable, so in whole my snippet is legal C++. Am i correct?
int main() {
const int& c = int();
int& m = const_cast<int&>(c);
m = 4;
}
The object of the snippet is to get a mutable reference to a temporary.
This cant be done directly because non-const reference cannot bind to
temporary, but we should be OK with casting away constness of reference
'c' since it doesn't actually refer to const object.
Temporaries are mutable, so in whole my snippet is legal C++. Am i correct?