Propagate constness to data pointed by member variables

前端 未结 4 1632
难免孤独
难免孤独 2020-12-14 16:41

It is often quite confusing to C++ newcomers that const member functions are allowed to call non-const methods on objects referenced by the class (either by pointer or refer

4条回答
  •  感动是毒
    2020-12-14 17:16

    For the record, I just found out that the Loki library does provide a const propagating pointer (ConstPropPtr). It looks just like the one in the question, except that it also deletes the wrapped pointer in its destructor, and it is used to implement a Pimpl class similar to the one proposed by @Matthieu (but not copyable).

提交回复
热议问题