I am trying to declare the object 'bst' from the class BST that is in another FILE. I am having trouble getting it to work. So far this is the error message when I try to compile the files.
$ make -f makefile.txt
g++ -Wall -W -Werror -pedantic -g -c BSTapp.cpp
BSTapp.cpp: In function `int main()':
BSTapp.cpp:9: error: `BST' undeclared (first use this function)
BSTapp.cpp:9: error: (Each undeclared identifier is reported only once for each function it appears in.)
BSTapp.cpp:9: error: expected `;' before "bst"
makefile.txt:5: recipe for target `BSTapp.o' failed
make: *** [BSTapp.o] Error 1
these are the files starting with.... BST.h
#ifndef BST_H_INCLUDED
#define BST_H_INCLUDED
#include <iostream>
#include <string>
using namespace std;
class BST
{
public:
BST();
~BST();
void insert(int key, string data);
void find(int key);
void remove(int key, string data);
void print();
friend class Node;
private:
Node* m_root;
};
#endif // BST_H_INCLUDED
bst.cpp
#include "BST.h"
void BST::insert(int key, string data)
{
}
bstapp.cpp (main)
#include "BSTapp.h"
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
BST bst; //<<this is where I am trying to declare the object.
cout << "hi" << endl;
cout << "in main" << endl;
string line;
string command = "aaaa";
string strKey;
string data;
//char ignore[] = "/";
while(command != "quit")
{
cout << "in while loop" << endl;
cin >> command;
cout << "Command is:" << command << endl;
if(command == "insert")
{
cin >> strKey;
strKey.erase(2, 1);
int intKey = atoi(strKey.c_str());
cout << intKey << endl;
cin.ignore();
getline(cin, data);
cout << data << endl;
}
if(command == "find")
{
}
if(command == "delete")
{
}
if(command == "print")
{
}
}
return 0;
}
BSTapp.h
#ifndef BSTAPP_H_INCLUDED
#define BSTAPP_H_INCLUDED
#include <string>
#include <iostream>
using namespace std;
/*class NodeData
{
public:
NodeData(int key, string data)
{m_key = key; m_data = data;}
//~NodeData(); // add this in eventually
private:
int m_key;
string m_data;
};*/
class BSTapp
{
public:
private:
};
#endif // BSTAPP_H_INCLUDED
the friend Node is declared as this...
#ifndef NODE_H_INCLUDED
#define NODE_H_INCLUDED
#include <iostream>
#include <string>
using namespace std;
class Node
{
public:
Node(int key, string data)
{m_key = key; m_data = data;}
~Node();
//friend BST();
private:
int m_key;
string m_data;
Node *m_left;
Node *m_right;
//Node *m_parent;
};
#endif // NODE_H_INCLUDED
basically, I just want to declare an object in int main so I can construct a new Node in BST (the assignment requires me to use all of these files so i cant just put everything into a .h and a .cpp, it has to be 6). Again, I am having trouble finding out how to declare an object in main. please tell me if i left any information out of this that you need, I am really bad at asking questions on this site.