C++ Inheritance

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

derived_constructor_name (parameters) : base_constructor_name (parameters) {...}

Syntax for calling a different constructor of a base class

All members that were public in Mother would become protected in Daughter. This would not restrict Daughter from declaring its own public members.

What does inheritance look like in the case of: class Daughter: protected Mother;

its constructors and its destructor its assignment operator members (operator=) its friends its private members

What is inherited from a base class?

In daughter case, nothing specified: call default constructor In son case, constructor specified: call this specific constructor

What is the difference between Daughter (int a) and Son (int a) : Mother (a)

Mother: no parameters Daughter: int parameter Mother: int parameter Son: int parameter

What is the output of the following: // constructors and derived classes #include <iostream> using namespace std; class Mother { public: Mother () { cout << "Mother: no parameters\n"; } Mother (int a) { cout << "Mother: int parameter\n"; } }; class Daughter : public Mother { public: Daughter (int a) { cout << "Daughter: int parameter\n\n"; } }; class Son : public Mother { public: Son (int a) : Mother (a) { cout << "Son: int parameter\n\n"; } }; int main () { Daughter kelly(0); Son bud(0); return 0; }

20 10

What is the output of the following: // multiple inheritance #include <iostream> using namespace std; class Polygon { protected: int width, height; public: Polygon (int a, int b) : width(a), height(b) {} }; class Output { public: static void print (int i); }; void Output::print (int i) { cout << i << '\n'; } class Rectangle: public Polygon, public Output { public: Rectangle (int a, int b) : Polygon(a,b) {} int area () { return width*height; } }; class Triangle: public Polygon, public Output { public: Triangle (int a, int b) : Polygon(a,b) {} int area () { return width*height/2; } }; int main () { Rectangle rect (4,5); Triangle trgl (4,5); rect.print (rect.area()); Triangle::print (trgl.area()); return 0; }


Kaugnay na mga set ng pag-aaral

243 PrepU Ch. 27 Anxiety Disorders: Management of Anxiety and Panic

View Set

TCP/IP Illustrated - Chapter 2 - IPv4 Multicast

View Set

Interest-Sensitive and Combination Plan Products

View Set

HBS - Lessons 3.3 and 3.4 Assessment

View Set

CH 11: Advanced Inheritance Concepts

View Set

CAPITOLUL 1 INTRODUCERE ÎN ANATOMIE SI FIZIOLOGIE

View Set

Chapter 6: Diseases and Disorders of Cardiovascular System

View Set

Psych Final (chapters 6, 7, and 11)

View Set

Anatomía (introducción a la Anatomía)

View Set

Ch 22 Care of Patients with Cancer

View Set

INTB 3355 SmartBook Module 5: Political Forces

View Set