-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStack.hpp
52 lines (44 loc) · 930 Bytes
/
Stack.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
** EPITECH PROJECT, 2024
** ppool13
** File description:
** Stack
*/
#pragma once
#include <exception>
#include <stack>
class Stack
{
public:
void push(double value);
double pop();
double top() const;
void add();
void sub();
void mul();
void div();
class Error : public std::exception
{
public:
enum class ErrorType
{
NOT_ENOUGH_OPERANDS,
EMPTY_STACK,
};
Error(ErrorType type) : _type(type) {}
const char *what() const noexcept override
{
switch (_type) {
case ErrorType::NOT_ENOUGH_OPERANDS:
return "Not enough operands";
default:
case ErrorType::EMPTY_STACK:
return "Empty stack";
}
}
private:
ErrorType _type;
};
private:
std::stack<double> _stack;
};