Hi, I just joined the community!
I have been implementing a Binary Search Tree Class. There are two classes, one is BSTNode which only has data,*left & right. Methods are functions to manipulate the tree are in BST.
While i was trying to compile using Dev-C++ 4,9,9,2 I receive the error of: [Linker error] undefined reference to `BSTNode::BSTNode(int const&, BSTNode*, BSTNode*)'
It does not indicate the line, and my all methods are defined inline, I do not get why the error contains "BSTNode::"..
#include <iostream>
usingnamespace std;
class BSTNode
{
public:
BSTNode* left;
BSTNode* right;
int item;
BSTNode (constint &item, BSTNode *lptr=NULL, BSTNode *rptr=NULL ); // Constructor for BSTNode class
};
class BST
{
public:
BST(constint item, BSTNode *root=NULL);
int InsertValue(BSTNode *root, int newitem) // Inserting an integer to an existing tree..
{
if ( root == NULL )
root=new BSTNode(newitem);
else
{
if ( newitem < root->item ) // If new value is smaller
InsertValue(root->left, newitem ); // Add to the left.
else // If new value is greater or equal
InsertValue(root->right, newitem ); // Add to the right.
}
}
You can't overload the constructor like that since the first one has defaults for the last two parameters which would result in an ambiguous call if you attempted to write the line of code Dacster13 gave.
Where is the implementation of the constructor defined on line 10 in the original code?
There were some global scale methods and there were pointers defined as BSTNode in main function but i did not paste here since it will be too long and messy.
Do you guess it is something with implementation of constructor?