В моей программе на C ++ (я знаю, что у меня должны быть файлы заголовков и прочее, но это формат, запрошенный учителем), в нем есть ошибка компиляции no matching function call for enqueue
, и я попытался использовать. и -> операторы. Скриншоты и код ниже. Я хотел бы знать, почему я получаю эту ошибку и как ее избежать в будущем.
#include <iostream>
#include <string>
using namespace std;
struct plane
{
string name;
char state;
//time
};
struct Queue // creation of queue for landing
{
int front, end, size;
unsigned capacity; // makes an integer var that cannot be negative
plane* planearray;// * and [] are synonymous
};
//Queue operator =(plane* array, const Queue& queue)
//{
//}
plane* createplane(char state, string name)
{
cout<<"Enter the plane's name";
cin>>name;
cout<<"Is the plane landing or taking off? 'T t (takeoff)' or 'L l(landing)' "<<endl;
cin>>state;
}
// function to create a queue of a given size
/*Why pointer in obj creation*/
Queue* createQueue(unsigned capacity) // takes in capacity because you want to modify it
{
char takeoffland;
cout<<"Is this a takeoff or landing queue? enter 'T t (takeoff)' or 'L l(landing)' "<<endl;
cin>>takeoffland;
if(takeoffland=='T'||takeoffland=='t')
{
Queue* tqueue = new Queue();
tqueue->capacity=capacity;
tqueue->front=tqueue->size = 0;
tqueue->end = capacity -1;
/*website has algorithm as [(queue->capactiy*sizeof(class)] looked up sizeof to be size of the data type but dont quite get it still */
tqueue->planearray = new plane[(tqueue->capacity)];
return tqueue;
}
else if(takeoffland=='L'||takeoffland=='l')
{
Queue* lqueue = new Queue();
lqueue->capacity=capacity;
lqueue->front=lqueue->size = 0;
lqueue->end = capacity -1;
/*website has algorithm as [(queue->capactiy*sizeof(class)] looked up sizeof to be size of the data type but dont quite get it still */
lqueue->planearray = new plane[(lqueue->capacity)];
return lqueue;
}
else{
cout<<"Invalid input try again";
}
}
bool isFull(Queue* queue)
{
if(queue->size == queue->capacity)
{
cout<<"The queue is full";
return true;
}
else{
return false;
}
}
bool isEmpty(Queue* queue)
{
if(queue->size == 0)
{
cout<<"The queue is empty";
return true;
}
else
{
return false;
}
}
void enqueue(Queue* queue, plane* p)
{
if(isFull(queue))
{
cout<<"Cannot add to queue, its full";
return;
}
plane* insert = p;
queue->end = queue->end+1;// makes end the very end
queue->planearray[queue->end] = *insert;// makes the end the new addition to queue
queue->size += 1;
if(p->state=='t'||p->state=='T')
{
cout<<"Plane added to takeoff queue"<<endl;
}
else if(p->state=='L'||p->state=='l')
{
cout<<"Plane added to landing queue"<<endl;
}
}
int main(){
Queue* landing = createQueue(1);
plane p1;
enqueue(landing, p1);
};