I am working on a basic BST project for my own reference. I have three files: BST.h, BST.cpp and main.cpp.
Inside BST.h it looks like so:
#pragma once
class BST {
private:
struct node {
int key; int data; node* left; node* right };
node* root;
node* CreateLeaf(int key, int data);
void AddLeafPrivate(int key, int data, node* newNode);
void PrintInOrderPrivate(node* nodePtr);
public:
BST();
void AddLeaf(int key, int data);
void PrintInOrder();
};
And inside BST.cpp I have the formal definitions for all of these functions, etc... an example being:
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include "BST.h"
using namespace std;
BST::BST() {
root = NULL;
}
the main.cpp file is currently empty. It only has includes and main() with return 0.
When I try to build this solution, I get LNK2005 errors for each of the functions I have created, something that didn't seem to happen until after I had finished the code for the PrintInOrderPrivate definition. I know that LNK2005 is typically caused by multiple definitions of functions across files, but I don't define anything in BST.h, only prototype. The errors all look something like this:
Severity Code Description Project File Line Suppression State Error LNK2005 "public: __thiscall BST::BST(void)" (??0BST@@QAE@XZ) already defined in BST.obj BasicBinarySearchTreeReference C:\Users\guita\documents\visual studio 2015\Projects\BasicBinarySearchTreeReference\BasicBinarySearchTreeReference\main.obj 1
I also get a LNK1169 error that I can't decipher.
Any insight as to why I am getting these errors is greatly appreciated, I'm really trying to understand BST's better, and this is currently in my way.
Thanks!