chore: Add course material
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
#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;
|
||||
Reference in New Issue
Block a user