我想把它从boost::shared_ptr中剔除,但我boost::const_pointer_cast不是答案.boost::const_pointer_cast想要const boost::shared_ptr<T>,而不是boost::shared_ptr<const T>。让我们放弃“你不应该那样做”的义务。我知道..。但我得这么做..。那么,做这件事最好/最简单的方法是什么?
为了清楚起见:
boost::shared_ptr<const T> orig_ptr( new T() );
boost::shared_ptr<T> new_ptr = magic_incantation(orig_ptr);我需要知道magic_incantation()
发布于 2010-06-10 01:13:56
boost::const_pointer_cast是您想要使用的函数:
boost::shared_ptr<const int> ci(new int(42));
boost::shared_ptr<int> i(boost::const_pointer_cast<int>(ci));这对你不管用吗?我测试了Boost 1.43和VisualC++2010 C++0x实现--两者都没有问题。
发布于 2010-06-10 07:28:15
请注意,如果共享const T突然发生变化,其他“股东”将感到非常惊讶.
https://stackoverflow.com/questions/3011023
复制相似问题