I want to create class for binary trees:
struct TreeNode {
explicit TreeNode(int _value) : value(_value) {}
int value = 0;
TreeNode* left = nullptr;
TreeNode* right = nullptr;
};
class BTree {
public:
void Add(int value);
void PrintPostOrder(void (*func)() = print_current);
~BTree();
private:
TreeNode* root = nullptr;
void print_current();
void delete_node();
};
BTree::~BTree() {
PrintPostOrder(delete_node);
}
My idea - for destructor and for Printing I need to do binary tree traversal. So I want to create function Traversal and use function as parameter in it:
if I need to print func = print and for destructor func = delete_node.
Error is here:
void PrintPostOrder(void (*func)() = print_current);
the default argument of type "void (BTree :: ) ()" is incompatible with the parameter of type "void () ()"
I don't know how to set default value for parameter when parameter is a function.
member function pointertag, because I always find it weird when the tags already have half of the answer)