Question
Assuming class Item { private: string name_; Item ( ); Item (string name) ; }; class Product : public Item { private: float price_ ;
Assuming
class Item {
private:
string name_;
Item ( );
Item (string name) ;
};
class Product : public Item {
private:
float price_ ;
public:
Product ( string name, float price );
};
Item::Item ( ) : name_ ("N/A" ) { }
Item::Item ( string name) : name_ (name) { }
Student A defines the Product constructor as follows:
Product::Product (float price) : price_ (price) { }
Student B defined the Product constructor as follows:
Product::Product ( string name, float price) : Item (name) , price_ (price) { }
1. What's the difference between student A and student B's constructor definitions?
2. Is there any problem with student A's definition when a Product object is created? Will the base class Item constructor get called? Explain if you think it will or it will not.
3. What's the value of the member data name_ when a Product object is created
using student A's definition: Product product ("iPhone", 959.99);
using student B's definition: Product product ("Smart TV", 459.59);
If you think name_ is not initialized then state so. Otherwise specify its value on each case.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started