I made a simple binary tree then decide to try out threads too. I got the following error:
call of an object of a class type without appropriate operator or conversion
Code:
#include "Tree.h"
#include <iostream>
#include <thread>
void main(void){
Tree tree;
for (int i = 0; i <= 25; i++)
{
tree.insert(i);
}
std::thread t1;
std::thread t2;
t1(tree.inorder());
t2(tree.inorder());
t1.join();
t2.join();
system("PAUSE");
}
Code:
#include "Tree.h"
#include <iostream>
Tree::Tree()
{
}
Tree::~Tree()
{
}
void Tree::insert(Node* leaf,int key){
if (key < leaf->num){
if (leaf->left != NULL){
insert(leaf->left, key);
}
else{
leaf->left = new Node;
leaf->left->num = key;
leaf->left->left = NULL;
leaf->left->right = NULL;
}
}
else if (key >= leaf->num){
if (leaf->right != NULL){
insert(leaf->right, key);
}
else{
leaf->right = new Node;
leaf->right->num = key;
leaf->right->left = NULL;
leaf->right->right = NULL;
}
}
}
void Tree::insert(int num){
if (root != NULL){
insert(root,num);
}
else{
root = new Node();
root->num = num;
root->left = NULL;
root->right = NULL;
}
}
void Tree::search(int num){
}
void Tree::print(){
}
void Tree::inorder(Node* leaf){
if (leaf != NULL){
inorder(leaf->left);
std::cout << leaf->num << "\n";
inorder(leaf->right);
}
}
void Tree::inorder(){
inorder(root);
}
void Tree::postorder(){
}
void Tree::preorder(){
}
I am having a hard time figuring out why the error exists. I tried adding the new operator but that did not work.
advice?