I'm trying to write a program that creates a Binary Tree data structure but I'm getting these weird compiler errors:
main.o:main.cpp:(.text+0x15): undefined reference to `BSTree::BSTree()'
main.o:main.cpp:(.text+0x15): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `BSTree::BSTree()'
collect2: error: ld returned 1 exit status
I don't really have any experience with this sort of compiler error and can't really figure out what could be wrong. As far as I can tell I've written similar code for other projects which compile fine.
This is my code:
main.cpp
#include <iostream>
#include <cstdlib>
#include "BSTree.h"
using namespace std;
int main()
{
BSTree treeValues;
return 0;
}
BSTree.h
#include <cstdlib>
#include "BTNode.h"
using namespace std;
class BSTree
{
public:
BSTree();
void add(int);
private:
BTNode* m_root;
int m_size;
};
BSTree.cpp
BSTree::BSTree()
{
m_root = NULL;
m_size = 0;
}
void BSTree::add(int it)
{
m_root = new BTNode(it);
}
BTNode.h
#include <cstdlib>
using namespace std;
class BTNode
{
public:
BTNode(int);
private:
int m_data;
BTNode* m_left;
BTNode* m_right;
BTNode* m_parent;
};
BTNode.cpp
BTNode::BTNode(int data)
{
m_data = data;
m_left = NULL;
m_right = NULL;
m_parent = NULL;
}
EDIT: fixed error message and formatting on .cpp files