PJF16

PersonInheritance

May 26th, 2015
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. //Person.h
  2.  
  3.     #pragma once
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. class Person {
  9. private:
  10.     string name;
  11.     int alter;
  12.  
  13. public:
  14.     Person (string n, int a);
  15.  
  16.     virtual string getName () const;
  17.  
  18.     virtual int getAlter () const;
  19.  
  20.     friend ostream& operator<< (ostream& out, const Person &p);
  21. };
  22.  
  23. //Person.cpp
  24.  
  25. #include "Person.h"
  26.  
  27.  
  28.     Person::Person (string n, int a) : name (n), alter (a) {};
  29.  
  30.     string Person:: getName () const {
  31.         return this->name;
  32.     }
  33.  
  34.      int Person::getAlter () const {
  35.         return this->alter;
  36.     }
  37.  
  38.     ostream& operator<< (ostream& out, const Person &p) {
  39.         out << "Name: " << p.name << " Alter: " << p.alter << endl;
  40.  
  41.         return out;
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment