Notice
Recent Posts
Recent Comments
Creative Code
main.cpp(employee클래스) 본문
※main.cpp파일
#include <iostream>
#include "employee.h"
int main() {
Employee *pEmployees[5];
pEmployees[0] = new Employee(1,"Park Jung Seok ",0);
pEmployees[1] = new Employee(2,"Sung Young Ho",pEmployees[0]);
pEmployees[2] = new Employee(3,"Sim Sung Suk",pEmployees[0]);
pEmployees[3] = new Employee(4,"Choi Su Gil",pEmployees[2]);
pEmployees[4] = new Employee(5,"Kim Young Gin",pEmployees[0]);
for (int i = 0; i<5; i++) {
std::cout << pEmployees[i] -> getId() << ", " << pEmployees[i] -> getName() << " : " ;
if (pEmployees[i] -> isManager()) std::cout << "None";
else std::cout << pEmployees[i]->getManager() ->getName();
std::cout << std::endl;
}
return 0;
for (int i = 0; i<5; i++) {
delete pEmployees[i];
}
}
※employee.h파일
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include "string.h"
class Employee {
private:
int id;
String name;
const Employee *pManager;
Employee(const Employee& rhs); //컴파일러가 자동으로 생성한 함수 중 쓰고싶지 않은 함수는 private에 선언만 해 둔다.
Employee& operator=(const Employee& rhs);
public:
//Employee() { }
Employee(int id, String name, const Employee *pManager);
//~Employee() { }
//Employee *operator&() { return this; }
//const Employee *operator&() const { return this; }
int getId() const;
String getName() const;
const Employee *getManager() const;
bool isManager() const;
};
#endif
※employee.cpp 파일
#include "employee.h"
Employee::Employee(int id, String name, const Employee *pManager) {
this->id = id;
this->name = name;
this->pManager = pManager;
}
int Employee::getId() const {
return this->id;
}
String Employee::getName() const {
return this->name;
}
const Employee *Employee::getManager() const {
return this->pManager;
}
bool Employee::isManager() const {
return this->pManager == 0;
}
'C++ Programming' 카테고리의 다른 글
main.cpp(rational클래스 증감연산자) (1) | 2023.09.04 |
---|---|
main.cpp(complex클래스 증감연산자) (0) | 2023.09.01 |
main.cpp(컴파일러가 자동생성하는 함수) (0) | 2023.09.01 |
main.cpp(string2) (0) | 2023.09.01 |
main.cpp(string) (0) | 2023.08.31 |