C++ smart pointer const correctness

后端 未结 5 1195
你的背包
你的背包 2020-12-24 10:56

I have a few containers in a class, for example, vector or map which contain shared_ptr\'s to objects living on the heap.

For example

template 

        
5条回答
  •  半阙折子戏
    2020-12-24 11:38

    one thing to realize is that:

    tr1::shared_ptr is mimicking the functionality of T const * namely what it points to is const, but the pointer itself isn't.

    So you can assign a new value to your shared pointer, but I would expect that you wouldn't be able to use the dereferenced shared_ptr as an l-value.

提交回复
热议问题