Chapter 15: Problem 12
Why can't we assign a base class object to a derived class variable?
Short Answer
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.
/*! This file is auto-generated */ .wp-block-button__link{color:#fff;background-color:#32373c;border-radius:9999px;box-shadow:none;text-decoration:none;padding:calc(.667em + 2px) calc(1.333em + 2px);font-size:1.125em}.wp-block-file__button{background:#32373c;color:#fff;text-decoration:none}
Learning Materials
Features
Discover
Chapter 15: Problem 12
Why can't we assign a base class object to a derived class variable?
These are the key concepts you need to understand to accurately answer the question.
All the tools & learning materials you need for study success - in one app.
Get started for free
Give a definition for a class SmartBut that is a derived class of the base class Smart, which we reproduce for you here. Do not bother with winclude directives or namespace details. class smart \\{ public: Smart( ) : void print_answer() const; protected: int a : int \(b\) \(y\) This class should have an additional data field, crazy, that is of type bool, one additional member function that takes no arguments and returns a value of type \(b o o l,\) and suitable constructors. The new function is named is_crazy. You do not need to give any implementations, just the class definition.
Suppose the base class and the derived class each have a member function with the same signature. When you have a pointer to a base class object and call a function member through the pointer, discuss what determines which function is actually called-the base class member function or the derived-class function.
include and using directives are added)? void show_employee_data(const Employee object): int main( ) \(l\) HourlyEmpl… # Is the following program legal (assuming appropriate #include and using directives are added)? void show_employee_data(const Employee object): int main( ) \(l\) HourlyEmployee joe("Mighty Joe", \\[ \left." 123-45-6789^{\prime \prime}, \quad 2 \theta \cdot 5 \theta, \quad 4 \theta\right) \\] SalariedEmployee boss("Mr. Big Shot", "987-65-4321", 10500.50) ; show_employee_data(joe) show_employee_data(boss) return \(\theta\) \\} void show_employee_data(const Employee object) \\{ cout \(<<\) "Name: \("<<\) object.get_name( ) \(<<\) endl; cout \(<<\) "Social Security Number: \&< object.get_ssn( ) \(<<\) endl;
The class SalariedEmployee inherits both of the functions get_name and print_check (among other things) from the base class Employee, yet only the function declaration for the function print_check is given in the definition of the class SalariedEmployee. Why isn't the function declaration for the function get_name given in the definition of SalariedEmployee?
Give the definitions for the member function add_value, the copy constructor,
the overloaded assignment operator, and the destructor for the following
class. This class is intended to be a class for a partially filled array. The
member variable number_used contains the number of array positions currently
filled. The other constructor definition is given to help you get started.
#include
What do you think about this solution?
We value your feedback to improve our textbook solutions.