// Create polymorphic tree with a twist! // Its all logic (and, or, t, f, not) // But we also need a function that makes implication (or something) // Nope we dont, that means ownership or smart pointers or something #include #include #include using namespace std; class Node { public: Node() {}; virtual ~Node() = default; virtual bool eval() const = 0; private: }; class Negation : public Node { public: Negation(Node const& child) : child{child} {} bool eval() const override { return not child.eval(); } private: Node const& child; }; class Literal : public Node { public: Literal(bool value) : value{value} {} bool eval() const override { return value; } private: bool value; }; class BinaryNode : public Node { public: BinaryNode(Node const& lhs, Node const& rhs) : lhs{lhs}, rhs{rhs} {} virtual bool eval() const = 0; protected: Node const& lhs; Node const& rhs; }; class Conjunction : public BinaryNode { public: Conjunction(Node const& lhs, Node const& rhs) : BinaryNode{lhs, rhs} {} bool eval() const override { return lhs.eval() and rhs.eval(); } private: }; class Disjunction : public BinaryNode { public: Disjunction(Node const& lhs, Node const& rhs) : BinaryNode{lhs, rhs} {} bool eval() const override { return lhs.eval() or rhs.eval(); } private: }; int main() { Literal a{false}; Literal b{true}; Literal c{false}; Disjunction disjunction{a, b}; Negation negation{c}; Conjunction conjunction{disjunction, negation}; std::cout << std::boolalpha << conjunction.eval() << std::endl; }