If I have a class, say,
class Car {
public:
void Drive();
void DisplayMileage() const;
};
And I create a shared pointer based on this class,
typedef boost::shared_ptr<Car> CarPtr;
And I then go on to populate a vector of CarPtrs,
std::vector<CarPtrs> cars...;
I now want to iterate over the vector and do some stuff:
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.
}
Is this possible without casting the shared pointer to a car to a shared pointer to a const car?