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!
#include "BinaryHeap.h"
#include <iostream>
#include <string>
usingnamespace 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();
}
elseif (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);
}
elseif (sCommand == "c")
{
P1.removeMin();
}
elseif (sCommand == "d")
{
// P1.Remove();
}
elseif (sCommand == "e")
{
// P1.IncreasePriority();
}
elseif (sCommand == "f")
{
// P1.DecreasePriority();
}
elseif (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
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.
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;
}