Skip to content

Commit 82e55ff

Browse files
committed
🐛 Bug fix for C++ calculator returns.
This was due to not compiling the calculator.cpp file after making changes to the calculator.hpp file.
1 parent a1117c9 commit 82e55ff

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

cpp/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@
3131
*.out
3232
*.app
3333

34-
/build/
34+
build/

cpp/calculator/calculator.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,28 @@ using namespace std;
88

99
shared_ptr<expression> expression::operator+(
1010
const shared_ptr<expression>& other) const {
11-
return make_unique<evaluation>(shared_from_this(), other, "+",
11+
return make_shared<evaluation>(shared_from_this(), other, "+",
1212
[](int a, int b) { return a + b; });
1313
}
1414

1515
shared_ptr<expression> expression::operator-(
1616
const shared_ptr<expression>& other) const {
17-
return make_unique<evaluation>(shared_from_this(), other, "-",
17+
return make_shared<evaluation>(shared_from_this(), other, "-",
1818
[](int a, int b) { return a - b; });
1919
}
2020

2121
shared_ptr<expression> expression::operator*(
2222
const shared_ptr<expression>& other) const {
23-
return make_unique<evaluation>(shared_from_this(), other, "*",
23+
return make_shared<evaluation>(shared_from_this(), other, "*",
2424
[](int a, int b) { return a * b; });
2525
}
2626

27+
shared_ptr<expression> expression::operator/(
28+
const shared_ptr<expression>& other) const {
29+
return make_shared<evaluation>(shared_from_this(), other, "/",
30+
[](int a, int b) { return a / b; });
31+
}
32+
2733
expression::~expression() {}
2834

2935
literal::literal(int data) : data_(data) {}

cpp/calculator/calculator.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class expression : public enable_shared_from_this<expression> {
1616
shared_ptr<expression> operator+(const shared_ptr<expression>& other) const;
1717
shared_ptr<expression> operator-(const shared_ptr<expression>& other) const;
1818
shared_ptr<expression> operator*(const shared_ptr<expression>& other) const;
19+
shared_ptr<expression> operator/(const shared_ptr<expression>& other) const;
1920

2021
virtual shared_ptr<const expression> simplify() const = 0;
2122
virtual string to_string() const = 0;

0 commit comments

Comments
 (0)