Category : destructor

I implement a class RedBlackTree like this. My questions are at the end. template < class T, class Node = ft::treeNode<T>, class Type_Alloc = std::allocator<T>, class Node_Alloc = std::allocator<Node> > class RedBlackTree { public: typedef T value_type; typedef size_t size_type; RedBlackTree() : _tree_size(0), _alloc_node(Node_Alloc()), _root(NULL) {} ~RedBlackTree() { deleteTree(_root); } void deleteTree(Node* node) { if(node ..

Read more

I have a class that’s almost a binary tree except it doesn’t have a root. class Expr { typedef std::tuple<char, const Expr*, const Expr*> node; std::variant<int, Var*, node> val; Expr(char op, const Expr&, const Expr&); public: Expr(int x) : val(x) {}; Expr(Var& x) : val(&x) {}; Expr(const Expr& e); Expr* Clone() const { return new ..

Read more

I was playing around with classes in C++, specifically implementing a private constructor with a static "create" function that returns the object. // main.cpp #include <iostream> class Foo { public: static Foo create_foo() { Foo foo{}; std::cout << "Foo::create_foo():: Address of foo: " << &foo << std::endl; return foo; } private: Foo() { std::cout << ..

Read more

There are two .cpp files namely frontend.cpp(contains definition for FrontEnd class and some other additional functions) and backend.cpp(contains definition for Backend class) I want to use the methods of BackEnd class in most of the functions defined in the FrontEnd.cpp, so I have created a global object for the BackEnd class there. If I try ..

Read more