如果我有一個類,比如說,共享指針和指向的常量性對象
class Car {
public:
void Drive();
void DisplayMileage() const;
};
我創建基於此類別的共享指針,
typedef boost::shared_ptr<Car> CarPtr;
然後我去填充CarPtrs的載體,
std::vector<CarPtrs> cars...;
我現在要遍歷向量和做一些東西:
for(auto const &car : cars) {
car->DisplayMileage(); // I want this to be okay
car->Drive(); // I want the compilation to fail here because Drive isn't const.
}
這可能沒有將共享指針投射到共享指針到一輛車的共享指針?
'boost :: shared_ptr'? –
Pubby
2013-04-26 19:17:52
我想對const做這個特殊的迭代失敗,我可能想在另一次迭代中改變車子。 – 2013-04-26 19:19:50
http://stackoverflow.com/q/15164330/560648 http://stackoverflow.com/q/13464199/560648 – 2013-04-26 19:24:49