Binary Search Tree

I'm working on a BST that will hold an instance of a class called Employees. My Search Tree is displaying no errors, but I'm getting quite a few from my main and Employee info files.

Every instance of emp, node, and tree are giving me the error "declaration has no storage class or type specifier." Shouldn't Employees and BSTtemplate be the type specifier?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include "Employees.h"
#include "BSTtemplate.h"

using namespace std;

int main()
{
	cout << "Employee List" << endl;

	Employees emp;
	BSTtemplate<Employees> tree;

	//Insert nodes

	emp.setID(1021);
	emp.setName("John Williams");

	BSTtemplate<Employees>::TreeNode node;
	node.value = item;

	tree.insertNode(node);

	cin.get();

	return 0;
}


In my Employees file, I've been getting errors saying empName and idNum are undefined in the functions, when they are defined right above it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#pragma once
#ifndef EMPLOYEES_H
#define EMPLOYEES_H
#include<iostream>
#include<string>
#include "BSTtemplate.h"

using namespace std;

class Employees
{
private:
	int idNum;
	string empName;
public:
	Employees(void);
	~Employees(void);

	Employees(int id = 0, char* n = "N/A")	//Constructor
	{
		id = 0;
		n = " ";
		idNum = id;
		empName = n;
	}

	void setIDNum(int i)	
	{
		idNum = i;
	}

	void setName(char *n)
	{
		empName = n;
	}


Still troubleshoot, but I appreciate any help that can be offered.
I have been troubleshooting this last night and today, but still haven't figured out what exactly is causing all these errors.

I'm also getting errors for Employees when defining its class object and when defining the class object for BSTtemplate<Employees>.

Does anyone have any insight?

EDIT:
In main

Employees emp;

Gives me an error for emp, saying the Employees class has more than one default constructor, when it only has one. The other constructor takes a parameter.
Last edited on
Still absolutely stumped. Taking a break from troubleshooting, for now, but I still welcome any insight to what my problem is.
The other constructor takes a parameter.

You provide default values for both arguments so it can be called as Employees(), same as the other one. This is how it is ambiguous.

Your code for the class is cut off so can't see if that critical semi-colon at the end is there...

What other errors are there?
I'll post my Employees class in its entirety so you can see all of what's going on.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma once
#ifndef EMPLOYEES_H
#define EMPLOYEES_H
#include<iostream>
#include<string>
#include "BSTtemplate.h"

using namespace std;

class Employees;	//Foreward Declaration

class Employees
{
private:
int idNum;
string empName;

public:

friend class BSTtemplate<Employees>;

	Employees();
	~Employees();

	Employees(int id = 0, char* n = "N/A")	//Constructor
	{
		id = 0;
		n = " ";
		idNum = id;
		empName = n;
	}

	void setIDNum(int i)	
	{
		idNum = i;
	}

	void setName(char *n)
	{
		empName = n;
	}

	void setName(string n)
	{
		empName = n;
	}

	int getID()
	{
		return this->idNum;
	}

	bool operator==(int val)
	{
		return this->getID() == val;
	}

	string getName()
	{
		return empName;
	}

	bool operator==(const Employees& emply)
	{
		return this->idNum == emply.idNum;
	}

	bool operator > (const Employees& emply)
	{
		return this->idNum > emply.idNum;
	}

	bool operator < (const Employees& emply)
	{
		return this->idNum < emply.idNum;
	}

};
#endif 


Other errors I've got include errors for every instance of my 'this' pointer telling me 'this may only be used in a non-static member function' and every instance of operator in my overloaded operator functions telling me there are 'too few parameters for the operator function'.

I also get errors on empName and idNum telling me they're inaccessible, but they're listed as private to the class, meaning the functions should be able to access them, shouldn't they?

EDIT:
I also included BSTtemplate<Employees> as a friend class, but either I implemented it incorrectly, or making it a friend hasn't solved anything like I thought it might.
Last edited on
So, no hit on the constructor issue?

May we see some error code?
The only thing I'm getting about the constructor is in

Employees(int id = 0, char* n = "N/A") on the opening bracket beneath the function header, which is saying 'expected a declaration'.

1
2
3
4
5
6
7
Employees(int id = 0, char* n = "N/A")	//Constructor
	{
		id = 0;
		n = " ";
		idNum = id;
		empName = n;
	}


Otherwise, no, neither of the default constructors that come standard when I initiated the Employees class are showing errors.

I'm also getting an error for main that says 'end of file found before the left brace '{'.

I'm not entirely sure what you mean by 'error code'. I'm not sure I've ever picked that out to show it before. Can you give me an example?
Last edited on
I meant the error messages given by the compiler.
Example
1
2
3
4
5
int main()
{
    x = 3;
    return 0;
}

Errors given:

C:\myProgrammingProjects\main.cpp||In function 'int main()':|
C:\myProgrammingProjects\main.cpp|82|error: 'x' was not declared in this scope|
||=== Build finished: 1 errors, 1 warnings ===|

I am using code blocks where the procedure for copying the error codes is to right click in the error message window and select "copy contents to clipboard".

You can't give default values for both arguments here:Employees(int id = 0, char* n = "N/A")! Why are you assigning values to id and n in the constructor?
This would overwrite any values passed.

Why char* n = "N/A" ? why not string n = "N/A"?

You might have many problems.
Last edited on
I think you might be right, but here's what I get from my error in the output window(I've redacted my name from the files, because I'm paranoid like that):

c:\users\\desktop\assignment8_adv. c++\assignment8_adv. c++\main.cpp(38): fatal error C1075: end of file found before the left brace '{' at 'c:\users\\desktop\assignment8_adv. c++\assignment8_adv. c++\bsttemplate.h(129)' was matched

So it seems my biggest problem (at the moment) is the compiler detecting the end of file before the first brace in main.

EDIT:

Okay, I've managed to weed out A LOT of the errors (most of which were caused by a single misplaced bracket), but I still have a few left to deal with.
Last edited on
Good. Notice that error message tells you that the problem is in bsttemplate.h(129) <-- line 129

That's what I wondered, if the errors are in Employees.h or not.
The error was indeed in my BST template. I'm notorious for losing track of my brackets, unfortunately.

I'm having an entirely separate problem now, though. Unresolved externals, again to do with the default constructor and destructor in Employees.

main.obj : error LNK2019: unresolved external symbol "public: __thiscall Employees::~Employees(void)" (??1Employees@@QAE@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall Employees::Employees(void)" (??0Employees@@QAE@XZ) referenced in function _main
OK.

I'm sorry if you're not understanding my explanation of the problem with the constructor.

I tried explaining it twice and you aren't asking for clarification, so...
Good luck!
I'm trying to understand, but I'm not seeing what I'm doing wrong.

I really would appreciate it if you would clarify on the issue I'm having with the constructor.

I've rebuilt my constructor to this:

1
2
3
4
5
6
7
8
9
10
Employees();
	
	~Employees();
	

	Employees(int id, string n)	//Constructor
	{
		idNum = id;
		empName = n;
	}


I've built classes with a default constructor and a constructor like the one above before(I actually just looked back at an old assignment to make sure I hadn't mucked up something really basic), so I'm not understanding why this program is still giving me unhandled exceptions.

I really appreciate all the help thus far, I'm just not really seeing where I'm going wrong.
You're welcome for the help.

It's better for me than watching T.V. LOL

That new constructor should fix that issue.

Unhandled exceptions? So now that it builds, it crashes?

Bummer!

EDIT: To clarify regarding the constructor issue.

You can have this: Employees();
or this: Employees(int id = 0, string n = "N/A")
but not both. Why? Because they can both be called like this: Employees(). Perhaps in your previous project you did not have both.
Those linker errors you gave last are probably due to not giving definitions for Employees() and ~Employees().
Last edited on
Topic archived. No new replies allowed.