You are viewing a single comment's thread. Return to all comments →
Adding virtual keyword in front of get_price() in Hotel Room is enough.
class HotelRoom { public: HotelRoom(int bedrooms, int bathrooms) : bedrooms_(bedrooms), bathrooms_(bathrooms) {} virtual int get_price() { return 50*bedrooms_ + 100*bathrooms_; } private: int bedrooms_; int bathrooms_; }; class HotelApartment : public HotelRoom { public: HotelApartment(int bedrooms, int bathrooms) : HotelRoom(bedrooms, bathrooms) {} virtual int get_price() override{ return HotelRoom::get_price() + 100; } };
Seems like cookies are disabled on this browser, please enable them to open this website
Hotel Prices
You are viewing a single comment's thread. Return to all comments →
Adding virtual keyword in front of get_price() in Hotel Room is enough.