extending two parent classes : Inheritance Multiple « Class « C++






extending two parent classes

   
#include <iostream>
#include <string.h>
using namespace std;
class Cover 
{
 public:
   Cover(char *title) { strcpy(Cover::title, title); };
 protected:
   char title[256];
};

class Page 
{
 public:
   Page(int lines = 55) { Page::lines = lines; };
 protected:
   int lines;
   char *text;
};

class Book: public Cover, public Page 
{
 public:
   Book(char *author, char *title, float cost): Cover(title), Page(60) 
   {
    strcpy(Book::author, author);
    strcpy(Book::title, title);
    Book::cost = cost; 
   };
   void show_book(void) 
   { 
     cout << title << endl; 
     cout << author << '\t' << cost; 
   };
 private:
   char author[256];
   float cost;
};

int main(void)
{
   Book text("A", "B", 49.95);

   text.show_book();
}
  
    
    
  








Related examples in the same category

1.Directly inherit two base classes.Directly inherit two base classes.
2.Inherit two base classes.Inherit two base classes.
3.Inherit two classes: constructing and destructing sequenceInherit two classes: constructing and destructing sequence
4.Call parent constructors in multiple inheritance