Is it possible to “constify” a field of `std::pair` without hacks?

前端 未结 2 444
北海茫月
北海茫月 2021-01-19 22:55

In C++, the compiling the following code:

std::pair   x;
static_cast *> (&x);

gi

2条回答
  •  梦谈多话
    2021-01-19 23:46

    That's not a cast, but you can do the following:

    std::pair  x;
    std::pair y( x );
    

    This should work according to §20.2.2/4.

提交回复
热议问题