クラスがある場合は、次のように言います。
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.
}
車への共有ポインタをconst車への共有ポインタにキャストせずにこれは可能ですか?