Advertisement
Felanpro

Inheritance

Apr 10th, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. //Base class: Gives the stuff.
  6. class Mother
  7. {
  8. public:
  9.     Mother();
  10.     void sayname();
  11. };
  12.  
  13. //Derived class: Inherit the stuff.
  14. class Daughter: public Mother //Inherit the members from the class Mother.
  15. {
  16. public:
  17.     Daughter();
  18. };
  19.  
  20. int main()
  21. {
  22.     Mother mom;
  23.     mom.sayname();
  24.  
  25.     Daughter girl;
  26.     girl.sayname();
  27.  
  28.     return 0;
  29. }
  30.  
  31. void Mother::sayname()
  32. {
  33.     cout << "I am a roberts!" << endl;
  34. }
  35.  
  36. Mother::Mother()
  37. {
  38.  
  39. }
  40.  
  41. Daughter::Daughter()
  42. {
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement