42 lines
852 B
C++
42 lines
852 B
C++
#include "Person.h"
|
|
#include "PersonException.h"
|
|
#include "YoungPerson.h"
|
|
#include <iostream>
|
|
|
|
using std::cout;
|
|
|
|
Person::Person(std::string name, int age) : name(name), age(age) {
|
|
if (age < 0) {
|
|
throw PersonException("negative age");
|
|
}
|
|
|
|
cout << "Person ctor\n";
|
|
Count++;
|
|
}
|
|
|
|
Person::Person(const Person &) {
|
|
cout << "Copy ctor\n";
|
|
Count++;
|
|
}
|
|
|
|
Person::~Person() {
|
|
cout << "Person dtor\n";
|
|
Count--;
|
|
}
|
|
|
|
void Person::setSalary(int sal) {
|
|
if (sal < 0) {
|
|
throw PersonException("negative salary");
|
|
}
|
|
|
|
salary = sal;
|
|
}
|
|
|
|
int Person::GetCount() { return Count; }
|
|
|
|
std::unique_ptr<Person> Person::GetPerson(std::string name, int age) {
|
|
return age < 18 ? std::make_unique<YoungPerson>(name, age) : std::make_unique<Person>(name, age);
|
|
}
|
|
|
|
int Person::Count = 0;
|