I would like to understand a difference of the below two cases.
const uint32_t v0 = 0;
const uint32_t v1 = 1;
const_cast<uint32_t&>(v0) = v1;
std::cout << v0 << std::endl;
This results:
0
However,
struct S {
const uint32_t v0;
S() : v0( 0U ) {}
} s;
const_cast<uint32_t&>(s.v0) = v1;
std::cout << s.v0 << std::endl;
I get:
1
Regarding first case, why does "v0" remain 0?
Thanks in advance.