Apr 9, 2012 at 8:15pm UTC
So I have 6 linker errors which tell me some of my functions which are referenced in my .cpp file dont exist. These functions are in my .h file which I have included at the top of my .cpp file. This is how my project is set up:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//BST.h
class BinarySearchTree{
public :
//constructor and destructor
virtual void functiona(){};
virtual void functionb(){};
//overloaded operator
protected :
void functionC(){};
void functionD(){};
void functionE(){};
private :
int someValue;
};
1 2 3 4 5 6 7 8 9 10 11 12
//BST.cpp
#include "BST.h"
BinarySearchTree::BinarySearchTree(){
someValue = 1;
}
void BinarySearchTree::functiona{
functionE();
}
void BinarySearchTree::functionb{
functionD();
}
My compiler yells at me saying:
Error 33 error LNK2019: unresolved external symbol "protected: void __thiscall BinarySearchTree::functionE(class TreeNode *,void (__cdecl*)(class KeyedItem &))" (?postorder@BinarySearchTree@@IAEXPAVTreeNode@@P6AXAAVKeyedItem@@@Z@Z) referenced in function "public: virtual void __thiscall BinarySearchTree::functiona(void (__cdecl*)(class KeyedItem &))" (?postorderTraverse@BinarySearchTree@@UAEXP6AXAAVKeyedItem@@@Z@Z) C:\Users\izik\Documents\Visual Studio 2010\Projects\BSTInsertDelete\BST.obj BSTInsertDelete
What's going on here? Anyone have some speculations as to what I'm doing wrong?
Last edited on Apr 9, 2012 at 8:48pm UTC
Apr 9, 2012 at 8:25pm UTC
The linker says very clear that it did not find such functions.
Can you point out for example where did you define function
void __thiscall BinarySearchTree::functionE(class TreeNode *,void (__cdecl*)(class KeyedItem &))"
???
Last edited on Apr 9, 2012 at 8:26pm UTC
Apr 9, 2012 at 8:49pm UTC
Thanks for the reply. FunctionE is defined within the same class that function a is. I edited my original post to illustrate this.
Last edited on Apr 9, 2012 at 8:51pm UTC
Apr 9, 2012 at 8:57pm UTC
The linker searches the function that takes two parameters the first of them is TreeNode *. Check your program to see where you call the function.
Apr 9, 2012 at 9:23pm UTC
You didn't define functionE in the class; you declared it there. You need to define it in your cpp file like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
//BST.cpp
#include "BST.h"
BinarySearchTree::BinarySearchTree(){
someValue = 1;
}
void BinarySearchTree::functiona{
functionE();
}
void BinarySearchTree::functionb{
functionD();
}
void BinarySearchTree::functionE{
++someValue;
}
Last edited on Apr 9, 2012 at 9:23pm UTC