/* * employee.cpp * * Created on: 16.05.2013 * Author: trifon */ #include #include "employee.h" Employee::Employee() : salary(0) { position = new char[1]; position[0] = '\0'; cerr << "Employee()" << endl; } Employee::Employee(char const* _name, char const* _id, char const* _position, double _salary) : Person(_name, _id), salary(_salary), position(NULL) { setPosition(_position); cerr << "Employee(...)" << endl; } double Employee::getSalary() const { return salary; } char const* Employee::getPosition() const { return position; } void Employee::setSalary(double _salary) { salary = _salary; } void Employee::setPosition(char const* _position) { delete[] position; position = new char[strlen(_position)+1]; strcpy(position, _position); } void Employee::print() const { Person::print(); cout << *this; } ostream& operator<<(ostream& os, Employee const& e) { os << "Позиция: " << e.position << endl; os << "Заплата: " << e.salary << endl; return os; } void Employee::copyEmployee(Employee const& e) { setPosition(e.position); setSalary(e.salary); } void Employee::delEmployee() { delete[] position; } Employee::Employee(Employee const& e) : Person(e), position(NULL) { cerr << "copy Employee" << endl; copyEmployee(e); } Employee& Employee::operator=(Employee const& e) { if (this != &e) { cerr << "= Employee" << endl; Person::operator=(e); copyEmployee(e); } return *this; } Employee::~Employee() { cerr << "~Employee()" << endl; delEmployee(); }