printf("ho_tari\n");
Employee 본문
<main.cpp>
#include <iostream>
#include "employee.h"
int main()
{
//Employee e;
//Employee e = e1;
//e = e1;
//Employee employee[5];
Employee *pEmployees[5];
pEmployees[0] = new Employee(1, "hotari", 0);
pEmployees[1] = new Employee(2, "c++", pEmployees[0]);
pEmployees[2] = new Employee(3, "python", pEmployees[0]);
pEmployees[3] = new Employee(4, "matlab", pEmployees[2]);
pEmployees[4] = new Employee(5, "arduino", pEmployees[0]);
for (int i = 0; i < 5; ++i)
{
std::cout << pEmployees[i]->getId() << ", " << pEmployees[i]->getName() << " : ";
if (pEmployees[i]->isManager())
{
std::cout << "Node";
}
else
{
std::cout << pEmployees[i]->getManager()->getName();
}
std::cout << std::endl;
}
for (int i = 0; i < 5; ++i)
{
delete pEmployees[i];
}
return 0;
}
<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);
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;
}
/*
Employee::~Employee()
{
}
*/
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;
}
<compile 결과>
'C++' 카테고리의 다른 글
Rational4 (증감연산자) (0) | 2023.09.04 |
---|---|
Complex5 (타입캐스팅) (0) | 2023.09.04 |
Complex4 (증감연산자) (0) | 2023.09.02 |
Rational2 (여러연산자) (0) | 2023.09.02 |
Rational (사칙연산) (0) | 2023.09.02 |