Is it considered a good practice to define virtual get and set functions in C++?
问题 If I have a simple 2 level class hierarchy as, for instance, this one: // level 1 class Spare_Part{ private: string name; double price; public: Spare_Part(); string getName() { return name; } double getPrice() { return price; } virtual int getQuantity() { return -1; }; // may also define it as pure virtual }; //level 2 class On_hand : public Spare_Part{ private: int quantity; string location; public: On_hand(); int getQuantity(){ return quantity; } }; I want to have access to the member