更新时间:2022-06-01 01:04:46
这样的东西,可能是:
template <typename T>
class deep_const_ptr {
T* p_;
public:
deep_const_ptr(T* p) : p_(p);
T* operator->() { return p_;}
const T* operator->() const { return p_;}
};
class A {
deep_const_ptr<B> b = new B;
};
deep_const_ptr
在的一个$ c>的const方法,并像
>在非const方法中。进一步丰富课程将留给读者。 T *
const T * const
deep_const_ptr
behaves like a const T* const
pointer in A
's const methods, and like T*
in non-const methods. Fleshing the class out further is left as an exercise for the reader.