fix: changing rank to integer
This commit is contained in:
parent
19ffc5d295
commit
0e3f3a6e3b
3 changed files with 16 additions and 8 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/16 14:49:52 by rparodi #+# #+# */
|
/* Created: 2025/03/16 14:49:52 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/03/16 22:00:36 by rparodi ### ########.fr */
|
/* Updated: 2025/03/16 22:16:30 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -27,7 +27,7 @@ Bureaucrat::Bureaucrat(void) : _name("Roger"), _grade(150) {
|
||||||
* @param name the name of the Bureaucrat
|
* @param name the name of the Bureaucrat
|
||||||
* @param grade grade to start the carreer
|
* @param grade grade to start the carreer
|
||||||
*/
|
*/
|
||||||
Bureaucrat::Bureaucrat(std::string name, u_int8_t grade) : _name(name) {
|
Bureaucrat::Bureaucrat(std::string name, int grade) : _name(name) {
|
||||||
std::cout << "[Bureaucrat] Smart constructor called" << std::endl;
|
std::cout << "[Bureaucrat] Smart constructor called" << std::endl;
|
||||||
if (grade < 1) {
|
if (grade < 1) {
|
||||||
throw GradeTooHighException();
|
throw GradeTooHighException();
|
||||||
|
|
@ -68,7 +68,7 @@ Bureaucrat::~Bureaucrat() {
|
||||||
*
|
*
|
||||||
* @return grade (unsigned int 8bits)
|
* @return grade (unsigned int 8bits)
|
||||||
*/
|
*/
|
||||||
u_int8_t Bureaucrat::getGrade() const {
|
int Bureaucrat::getGrade() const {
|
||||||
return (this->_grade);
|
return (this->_grade);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/16 14:48:33 by rparodi #+# #+# */
|
/* Created: 2025/03/16 14:48:33 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/03/16 22:01:02 by rparodi ### ########.fr */
|
/* Updated: 2025/03/16 22:16:36 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -16,15 +16,21 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#define RESET "\033[0m"
|
||||||
|
#define YELLOW "\033[0;33m"
|
||||||
|
#define RED "\033[0;31m"
|
||||||
|
|
||||||
class Bureaucrat {
|
class Bureaucrat {
|
||||||
public:
|
public:
|
||||||
Bureaucrat(void);
|
Bureaucrat(void);
|
||||||
Bureaucrat(std::string name, u_int8_t grade);
|
Bureaucrat(std::string name, int grade);
|
||||||
Bureaucrat(Bureaucrat const ©);
|
Bureaucrat(Bureaucrat const ©);
|
||||||
Bureaucrat& operator=(Bureaucrat const &assign);
|
Bureaucrat& operator=(Bureaucrat const &assign);
|
||||||
~Bureaucrat(void);
|
~Bureaucrat(void);
|
||||||
std::string getName(void) const;
|
std::string getName(void) const;
|
||||||
u_int8_t getGrade(void) const;
|
int getGrade(void) const;
|
||||||
|
void promote(void);
|
||||||
|
void demote(void);
|
||||||
class GradeTooHighException : public std::exception {
|
class GradeTooHighException : public std::exception {
|
||||||
virtual const char *what() const throw() {
|
virtual const char *what() const throw() {
|
||||||
return ("Error:\n> Grade is too high (have to be lower than 1)");
|
return ("Error:\n> Grade is too high (have to be lower than 1)");
|
||||||
|
|
@ -37,7 +43,7 @@ class Bureaucrat {
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
std::string _name;
|
std::string _name;
|
||||||
u_int8_t _grade;
|
int _grade;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, Bureaucrat const &bureaucrat);
|
std::ostream& operator<<(std::ostream& os, Bureaucrat const &bureaucrat);
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,9 @@ RM = rm -rf
|
||||||
# Mandatory flags for 42
|
# Mandatory flags for 42
|
||||||
CXXFLAGS = -Werror -Wextra -Wall -std=c++98 -I./includes/
|
CXXFLAGS = -Werror -Wextra -Wall -std=c++98 -I./includes/
|
||||||
# Flags to debug and have the dependences (can be removed for correction)
|
# Flags to debug and have the dependences (can be removed for correction)
|
||||||
CXXFLAGS += -MMD -g3
|
CXXFLAGS += -MMD
|
||||||
|
|
||||||
|
DEBUG += -g3 -fsanitize=address
|
||||||
|
|
||||||
# Sources
|
# Sources
|
||||||
SRC = Bureaucrat.cpp \
|
SRC = Bureaucrat.cpp \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue