Compilation errors for Binary Heap

Hi all! I have been trying to debug these syntax errors for hours now and cannot find the problem. Hopefully a fresh set of eyes can see where I am going wrong. Please help!

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
include <string>

using namespace std;

class BinaryMinHeap 
{
	private:

		struct Job
		{
			string name;
			string assign;
			int hours;
		};
		
		struct BinaryHeap
		{
			Job a[16];
		};

		BinaryHeap B1;
		int heapSize;
		int arraySize;
      
	public:
		BinaryMinHeap();
		int getLeftChildIndex(int);
		int getRightChildIndex(int);
        int getParentIndex(int);
		void percDown(int);
		void percUp(int);
		void insert(Job);
		void Print();
		void removeMin();
		~BinaryMinHeap(); 

};


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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include "BinaryHeap.h"
#include <string>
#include <iostream>

BinaryMinHeap::BinaryMinHeap() 
  {
  
     heapSize = 0;
     arraySize = 16;
  }     

int BinaryMinHeap::getLeftChildIndex(int nodeIndex) 
{
	return 2 * nodeIndex + 1;
}

int BinaryMinHeap::getRightChildIndex(int nodeIndex) 
{
    return 2 * nodeIndex + 2;
}

int BinaryMinHeap::getParentIndex(int nodeIndex) 
{
	return (nodeIndex - 1) / 2;
}

void BinaryMinHeap::percUp(int nodeIndex) 
{
	int parentIndex;
	Job tmp;
	if (nodeIndex != 0)
	{
		parentIndex = getParentIndex(nodeIndex);
		if (B1.a[parentIndex].name > B1.[nodeIndex].name) 
		{
			tmp = B1.a[parentIndex];
			B1.a[parentIndex] = B1.a[nodeIndex];
			B1.a[nodeIndex] = tmp;
			percUp(parentIndex);
		}
	}

}


void BinaryMinHeap::insert(Job J1)
{
	if (heapSize == arraySize)
		cout << "Heap is full" << endl;
	else 
	{
		heapSize++;
		B1.a[heapSize - 1] = J1;
		percUp(heapSize - 1);
	}
}

void BinaryMinHeap::percDown(int nodeIndex) 
{
	int leftChildIndex, rightChildIndex, minIndex;
	Job tmp;
	leftChildIndex = getLeftChildIndex(nodeIndex);
	rightChildIndex = getRightChildIndex(nodeIndex);
	if (rightChildIndex >= heapSize) 
	{
		if (leftChildIndex >= heapSize)
			return;
		else
			minIndex = leftChildIndex;

      } 
	else 
	{
		if (B1.a[leftChildIndex].name <= B1.a[rightChildIndex].name)
			minIndex = leftChildIndex;
		else
			minIndex = rightChildIndex;
	}
	if (B1.a[nodeIndex].name > B1.a[minIndex].name)
	{
		tmp = B1.a[minIndex];
		B1.a[minIndex] = B1.a[nodeIndex];
		B1.a[nodeIndex] = tmp;
		percDown(minIndex);
	}
}

void BinaryMinHeap::removeMin() 
{
	if (heapSize == 0)
	{
		cout << "Heap is empty" << endl;
	}
	else
	{
		B1.a[0] = B1.a[heapSize - 1];
		heapSize--;
		if (heapSize > 0)
		{
			percDown(0);
		}
	}
}

void BinaryMinHeap::Print()
{
 cout << "JOB NAME    "  << "ASSIGNEE    " << "HOURS    " << endl; 

 for (int i = 0; i < arraySize; i++)
 {
	 cout << B1.a[i].name << "    " << B1.a[i].assign << "     " << B1.a[i].hours << "     " << endl;
 }
}

 BinaryMinHeap::~BinaryMinHeap() 
 {}


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
#include "BinaryHeap.h"
#include <iostream>
#include <string>

using namespace std;

struct Job
{
	string name;
	string assign;
	int hours;
};

int main()
{
 BinaryMinHeap P1;
 Job J1;
 string sCommand;
 
 while (sCommand != "g")
 {
    cout << "*********************************************" << endl;
	cout << "a. List all the jobs in the queue" << endl;
	cout << "b. Add a new job to the queue" << endl;
	cout << "c. Release the next job in the queue" << endl;
	cout << "d. Remove a job from the queue" << endl;
	cout << "e. Increase the priority of a job" << endl;
	cout << "f. Decrease the priority of a job" << endl;
	cout << "g. Exit" << endl;
	cout << "*********************************************" << endl;
    cin >> sCommand;

	if (sCommand == "a")
	{
//		P1.Print();
	}
	else if (sCommand == "b")
	{
		cout << "Enter the name of the job: ";
		cin >> J1.name;
		cout << endl << "Enter whos this job is assigned to: ";
		cin >> J1.assign;
		cout << endl << "Enter the hours required to complete the job: ";
		cin >> J1.hours;
		P1.insert(J1);
	}
	else if (sCommand == "c")
	{
		P1.removeMin();
	}
	else if (sCommand == "d")
	{
//		P1.Remove();
	}
	else if (sCommand == "e")
	{
//		P1.IncreasePriority();
	}
	else if (sCommand == "f")
	{
//		P1.DecreasePriority();
	}
	else if (sCommand == "g")
	{
		return 0;
	}
	else 
	{
		cout << "Invalid Command" << endl;
	}
 }

}


1>Compiling...
1>BinaryHeap.cpp
1>c:\users\mike\documents\visual studio 2008\projects\bheap\bheap\testbinaryheap.cpp(45) : error C2664: 'BinaryMinHeap::insert' : cannot convert parameter 1 from 'Job' to 'BinaryMinHeap::Job'
1>        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Last edited on
The struct Job you declared on line 9 of BinaryHeap.h is a different one from the one declared on line 7 of testbinaryheap.cpp, even if their contents are identical.
Bah i was just about to write that lol
What can I do to fix this?
Well you can create the BinaryMinHeap::Job object directly (or typedef it to make it more readable) as long as it you also make it publicly available...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class BinaryMinHeap {
	private:
		// other private stuff
	public:
		struct Job {
			// data members
		}
	// other class stuff
}
typedef BinaryMinHeap::Job Job;

int main(void){
	Job j;
	// do stuff with the job...
	return 0;
}

(I haven't compiling this myself)
Topic archived. No new replies allowed.