I am trying to devise a program that fills an area of an image. Just for leaing and advancing in C++. However, I have this error which appears to be that I am the only one having this specific error. I basically have three files, all written by me. But I am posting only the relevant one here. I have commented the most relevant lines also. Here is the binarytree class:
#include<cstddef>
#include<iostream>
using namespace std;
template<typename T>
class binarytree {
struct node {
T val;
node* right;
node* left;
};
node** getToLeaf(node* &a, T b);
typedef int (binarytree<T>::*fptr)(T a, T b); //<- this lines produces a function pointer type
fptr fp; //<- Here is declaration of the function pointer object
node* root;
public:
binarytree();
//~binarytree();
void add(T a);
bool contains(T a);
void printAscending();
void printAscending(node* c);
void printDescending(node* c);
void printDescending();
int operatorfn(T a, T b); //<-This is the default comparison function
void setComparisonFN(int (*cmpfn)(T a, T b)); //used when client wants to manually set the compfn
};
template<typename T>
binarytree<T>::binarytree() {
root = NULL;
fp = operatorfn;//when the object is initialized, function pointer is set to the default operatorfn. I get an error here also.
}
template<typename T>
int binarytree<T>::operatorfn(T a, T b) {
if(a>b)
retu 1;
else if(a==b)
retu 0;
else
retu -1;
}
template<typename T>
void binarytree<T>::printAscending(node* c) {
if(c->left!=NULL)
printAscending(c->left);
cout<<c->val<<endl;
if(c->right!=NULL)
printAscending(c->right);
}
template<typename T>
void binarytree<T>::printDescending(node* c) {
if(c->right!=NULL)
printDescending(c->right);
cout<<c->val<<endl;
if(c->left!=NULL)
printDescending(c->left);
}
template<typename T>
void binarytree<T>::printDescending() {
printDescending(root);
}
template<typename T>
void binarytree<T>::printAscending() {
printAscending(root);
}
template<typename T>
void binarytree<T>::add(T addedValue) {
node** np = getToLeaf(root, addedValue);
*np = new node;
(*np)->val = addedValue;
(*np)->left = NULL;
(*np)->right = NULL;
}
//this function is used by the client to manually set their comparison function
//in case their data types can not be handled by the operatorfn function.
template<typename T>
void binarytree<T>::setComparisonFN(int (cmpfn)(T a, T b)) {
fp = cmpfn; //<- the error occurs on this line
}
template<typename T>
typename binarytree<T>::node** binarytree<T>::getToLeaf(node* & pointerToNode, T valueToGet) {
if (pointerToNode == NULL ||fp(pointerToNode->val, valueToGet)==0) //<-in this line, the function
//pointer begins its role
retu &pointerToNode;
else if (fp(valueToGet, pointerToNode->val)>0)
getToLeaf(pointerToNode->right, valueToGet);
else
getToLeaf(pointerToNode->left, valueToGet);
}
template <typename T>
bool binarytree<T>::contains(T a){
node** np=getToLeaf(root, a);
if(*np==NULL)
retu false;
retu true;
}
and here is the error I get, I think they all originate from one problem:
1> Source.cpp
1>c:usersyadidocumentsvisual studio 2012projectsbinary treebinary treebinarytree.h(37): error C3867: 'binarytree<T>::operatorfn': function call missing argument list; use '&binarytree<T>::operatorfn' to create a pointer to member
1> with
1> [
1> T=point
1> ]
1> c:usersyadidocumentsvisual studio 2012projectsbinary treebinary treebinarytree.h(35) : while compiling class template member function 'binarytree<T>::binarytree(void)'
1> with
1> [
1> T=point
1> ]
1> c:usersyadidocumentsvisual studio 2012projectspaint bucketpaint bucketsource.cpp(45) : see reference to function template instantiation 'binarytree<T>::binarytree(void)' being compiled
1> with
1> [
1> T=point
1> ]
1> c:usersyadidocumentsvisual studio 2012projectspaint bucketpaint bucketsource.cpp(33) : see reference to class template instantiation 'binarytree<T>' being compiled
1> with
1> [
1> T=point
1> ]
1>c:usersyadidocumentsvisual studio 2012projectsbinary treebinary treebinarytree.h(98): error C2440: '=' : caot convert from 'int (__cdecl *)(T,T)' to 'int (__thiscall binarytree<T>::* )(T,T)'
1> with
1> [
1> T=point
1> ]
1> There is no context in which this conversion is possible
1> c:usersyadidocumentsvisual studio 2012projectsbinary treebinary treebinarytree.h(97) : while compiling class template member function 'void binarytree<T>::setComparisonFN(int (__cdecl *)(T,T))'
1> with
1> [
1> T=point
1> ]
1> c:usersyadidocumentsvisual studio 2012projectspaint bucketpaint bucketsource.cpp(46) : see reference to function template instantiation 'void binarytree<T>::setComparisonFN(int (__cdecl *)(T,T))' being compiled
1> with
1> [
1> T=point
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
