PDA

View Full Version : BST & Function Pointer Errors...


Jammer
04-04-2002, 11:42 PM
Alright, I'm righting a Binary Tree class. I have it all done, but I have errors on my traversals. All of these are traversal which accept a node pointer and a void (*function) (itemType &target) function as a paramater. I get the follow errors:

error C2664: 'myInOrder' : cannot convert parameter 2 from 'void (int &)' to 'void (__cdecl *)(int &)' None of the functions with this name in scope match the target type while compiling class-template member function '__thiscall searchTree<int>::searchTree<int>(class searchTree<int> &)'

error C2664: 'myInOrder' : cannot convert parameter 2 from 'void (int &)' to 'void (__cdecl *)(int &)' None of the functions with this name in scope match the target type while compiling class-template member function 'void __thiscall searchTree<int>::printTree(int)'

error C2664: 'myPostOrder' : cannot convert parameter 2 from 'void (int &)' to 'void (__cdecl *)(int &)' None of the functions with this name in scope match the target type
while compiling class-template member function 'void __thiscall searchTree<int>::printTree(int)'

error C2664: 'myPreOrder' : cannot convert parameter 2 from 'void (int &)' to 'void (__cdecl *)(int &)' None of the functions with this name in scope match the target type while compiling class-template member function 'void __thiscall searchTree<int>::printTree(int)'

error C2664: 'myInOrder' : cannot convert parameter 2 from 'void (int &)' to 'void (__cdecl *)(int &)' None of the functions with this name in scope match the target while compiling class-template member function 'void __thiscall searchTree<int>::operator =(class searchTree<int> &)'


As you can see, they are all virtually the same. The errors are from compiling bstRun.cpp (http://mywebpages.comcast.net/jammer211/bstRun.cpp). This runs with bst.h (http://mywebpages.comcast.net/jammer211/bst.h) and bst.cpp (http://mywebpages.comcast.net/jammer211/bst.cpp).

Thanks, I'd appreciate any help you could offer.

MattD
04-07-2002, 12:56 AM
"C++ offers a facility for indirectly referring to a member of a class. A point to a member is a valuet that identifies a member of a class, you can think of it as the position of the member in an object of the class."

class Std_Interface{
virtual void suspend() = 0;
}

void f(Std_Interface *p){
Std_Interface::* s = &Std_Interface::suspend;
p->suspend(); //direct call
(p->*s)(); // call through pointer to member
}

(example lifted and slightly mod'd from pg 418 of bjarne stroustrups the c++ programming language 3rd ed)

of course, templates make all this function pointer stuff totally redundant. :) its quite trivial to implement a binary tree template class..

cheers

Matt D
-= sorry bout the messages :) =-

sans-hubris
04-07-2002, 04:07 AM
Can you post bst.h? The source to the header file would help.

Nafae
04-07-2002, 04:26 PM
MattD: Please do not triplepost. You can edit your threads and append whatever else you like to the original thread, but don't post one thread after the other.