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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!