0

So I am working on a custom binary search tree class and as of now, my main function in my cpp file is only this:

#include "stdafx.h"
#include "BST.h"
using namespace std;

int main()
{
    BST<string> tree;
    return 0;
}

but I'm getting three 2065 errors, one for the term "BST" one for "String" and one for "tree". I've tried to include the string class as well, but that doesn't change anything. I've been trying to understand what's going on for a long time but I can't wrap my head around it. Here's some basic code from my header file:

#pragma once
#ifndef BST_H
#define BST_H

#include <stdexcept>
#include <iostream>
#include <string>
using namespace std;

template <typename T>
class BST
{
    BST();
    BST(T elements[], int arraySize);
    BST(BST<T> &tree);
    //insert code here
};

I won't include the entire header file here because it's 400 lines, but it's not anything special. I have including BST.h in the header files in the visual studio solution and everything in the solution should be working properly. There are no errors when I comment out the line where the BST is declared. Any help with this is super appreciated, as visual studio and all of it's nuances are so confusing to me. Thank you.

user4581301
  • 29,019
  • 5
  • 26
  • 45
Ella
  • 93
  • 2
  • 8
  • What is the actual error message? – NathanOliver Jun 05 '18 at 20:12
  • have you trying define the templated class in the header file itself? – JeJo Jun 05 '18 at 20:13
  • 1
    stdafx.h MUST be the first include. Everything above it is ignored. – user4581301 Jun 05 '18 at 20:13
  • 1
    StdAfx.h must be included as the very first – sebrockm Jun 05 '18 at 20:14
  • As odd and tangential as that duplicate sounds, it is the most direct answer. Plus it contains some other fun and educational material. – user4581301 Jun 05 '18 at 20:16
  • @user4581301 I tried adding it as the first thing and it was the same errors – Ella Jun 05 '18 at 20:20
  • In that case you have a second bug somewhere. I will edit your question to reverse the includes and re-open. Make sure it's not because of the missing `#endif` in the header. Also note that in the shortened `BST` the functions are all `private`. – user4581301 Jun 05 '18 at 20:30
  • Once I fix the above mistakes, I am unable to produce anything but the linker errors resulting from the missing implementations. More information is required. Please produce a [mcve]. – user4581301 Jun 05 '18 at 20:33
  • Constructor of BST is private. So, you won't be able to create its instance in main – Wander3r Jul 15 '18 at 02:20

0 Answers0