CPP05 1.0
読み取り中…
検索中…
一致する文字列を見つけられません
Bureaucrat.hpp
[詳解]
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* Bureaucrat.hpp :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: kamitsui <kamitsui@student.42tokyo.jp> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2025/06/26 09:59:12 by kamitsui #+# #+# */
9/* Updated: 2025/06/29 05:46:29 by kamitsui ### ########.fr */
10/* */
11/* ************************************************************************** */
12
18#ifndef BUREAUCRAT_HPP
19#define BUREAUCRAT_HPP
20
21#include <iostream>
22#include <stdexcept>
23#include <string>
24
31
32 private:
33 const std::string _name;
34 int _grade;
35 // A default constructor is private because a Bureaucrat must have a name.
36 Bureaucrat();
37
38 public:
39 // Orthodox Canonical Form
40 Bureaucrat(const std::string &name, int grade);
41 Bureaucrat(const Bureaucrat &other);
42 Bureaucrat &operator=(const Bureaucrat &other);
44
45 // Getters
46 const std::string &getName() const;
47 int getGrade() const;
48
49 // Member functions
50 void incrementGrade();
51 void decrementGrade();
52
53 // --- Exception Classes ---
54 // These inherit from std::exception to be part of the standard exception hierarchy.
55 // They override the what() method to provide a descriptive error message.
56
58 public:
59 virtual const char *what() const throw();
60 };
61
63 public:
64 virtual const char *what() const throw();
65 };
66};
67
68// --- Operator Overload ---
69// Overload of the insertion (<<) operator for easy printing.
70std::ostream &operator<<(std::ostream &os, const Bureaucrat &bureaucrat);
71
72#endif
virtual const char * what() const
virtual const char * what() const
Represents a bureaucrat with a name and a grade.
void incrementGrade()
Increments the bureaucrat's grade (e.g., from 3 to 2).
void decrementGrade()
Decrements the bureaucrat's grade (e.g., from 2 to 3).
int getGrade() const
Gets the grade of the Bureaucrat.
~Bureaucrat()
Destroy the Bureaucrat:: Bureaucrat object
Bureaucrat & operator=(const Bureaucrat &other)
Assignment operator for Bureaucrat.
const std::string & getName() const
Gets the name of the Bureaucrat.
std::ostream & operator<<(std::ostream &os, const Bureaucrat &bureaucrat)
Overloads the << operator to print Bureaucrat information.