fix: changing rank to integer

This commit is contained in:
Raphael 2025-03-16 22:19:58 +01:00
parent 19ffc5d295
commit 0e3f3a6e3b
3 changed files with 16 additions and 8 deletions

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 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;
if (grade < 1) {
throw GradeTooHighException();
@ -68,7 +68,7 @@ Bureaucrat::~Bureaucrat() {
*
* @return grade (unsigned int 8bits)
*/
u_int8_t Bureaucrat::getGrade() const {
int Bureaucrat::getGrade() const {
return (this->_grade);
}

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <iostream>
#define RESET "\033[0m"
#define YELLOW "\033[0;33m"
#define RED "\033[0;31m"
class Bureaucrat {
public:
Bureaucrat(void);
Bureaucrat(std::string name, u_int8_t grade);
Bureaucrat(std::string name, int grade);
Bureaucrat(Bureaucrat const &copy);
Bureaucrat& operator=(Bureaucrat const &assign);
~Bureaucrat(void);
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 {
virtual const char *what() const throw() {
return ("Error:\n> Grade is too high (have to be lower than 1)");
@ -37,7 +43,7 @@ class Bureaucrat {
};
private:
std::string _name;
u_int8_t _grade;
int _grade;
};
std::ostream& operator<<(std::ostream& os, Bureaucrat const &bureaucrat);

View file

@ -22,7 +22,9 @@ RM = rm -rf
# Mandatory flags for 42
CXXFLAGS = -Werror -Wextra -Wall -std=c++98 -I./includes/
# Flags to debug and have the dependences (can be removed for correction)
CXXFLAGS += -MMD -g3
CXXFLAGS += -MMD
DEBUG += -g3 -fsanitize=address
# Sources
SRC = Bureaucrat.cpp \