What's the point of const pointers?

后端 未结 17 1876
粉色の甜心
粉色の甜心 2020-11-30 17:28

I\'m not talking about pointers to const values, but const pointers themselves.

I\'m learning C and C++ beyond the very basic stuff and just until today I realized t

17条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 17:57

    There's nothing special about pointers where you would never want them to be const. Just as you can have class member constant int values, you can also have constant pointers for similar reasons: You want to make sure that no one ever changes what's being pointed to. C++ references somewhat address this, but the pointer behavior is inherited from C.

提交回复
热议问题