0

In my C++ program (I know I should have header files and stuff but this is the teacher requested format) it has a compilation error no matching function call for enqueue and I've tried using . and -> operators as well. Screenshots and code below. I'd like to know why I'm getting that error and how to avoid it in the future.

#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);





};

error screenshot

1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56
  • 5
    You have a function with the signature `enqueue(Queue*, plane*)`. You're trying to call a function with the signature `enqueue(Queue*, plane)` Either change your function to accept a `plane` object (not a `plane` pointer), or pass a `plane` pointer to your current `enqueue` function. – JohnFilleau Mar 02 '20 at 17:12
  • 1
    I don’t know how much of the code, comments, and reference material *you* wrote (and you’re obviously just starting out, so it can’t really be your fault anyway), but you should know regardless that much of what is here is **awful** — the comments are wrong, the class design is, er, absent, there’s undefined behavior, it never uses `const`, and the use of raw pointers is causing all the standard resource issues. – Davis Herring Mar 02 '20 at 17:18
  • 1
    Create a [mcve] – eerorika Mar 02 '20 at 17:20
  • Unrelated: When you have a function named `createX`, what you probably want is an `X` constructor. – user4581301 Mar 02 '20 at 17:24
  • So being that my code is essentially not good how can I get to a point where I write solid c++ code. Im reading the book for class. Im studying the material I believe I understand structure logic and so forth but I struggle really bad with implementation. What can I do ( and im midway through data structures). – Luckthedev Mar 02 '20 at 17:27
  • There are a [bunch of good books](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) on designing and structuring code, but if you are a student, you probably can't afford any of them. Here is [a page of much wisdom that is free](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). The bulk of the work is practice, though. Why you want to create a [mcve]: it's a distillation of very powerful debugging techniques, and more often than not, you get about half way through making one and find and fix the problem yourself. – user4581301 Mar 02 '20 at 17:31
  • thank you I borrowed the code posted from https://www.geeksforgeeks.org/queue-set-1introduction-and-array-implementation/ and tried to tweak it to suit my assignment. I suppose thats not a good source? Or did I just duck the code haha. – Luckthedev Mar 02 '20 at 17:34
  • Geeks for Geeks is hit and miss, and some of the misses are spectacularly bad, probably due to poor editorial policy. In general, It is very hard to tell a good tutorial from a bad one until you know the material well enough to probably not need the tutorial. Bit of a Catch 22 there. – user4581301 Mar 02 '20 at 17:38
  • Note: `* and [] are synonymous` only applies in certain circumstances, most notably in a function's parameters where [the array has decayed to a pointer](https://stackoverflow.com/questions/1461432/what-is-array-decaying). An array is not a pointer; but it can be used as one. The rest of the time empty `[]`s are illegal in c++. An array must always know its size (and with a few non-Standard exceptions from compiler extensions) at compile time. In [C you can end a structure with `plane planearray[];`](https://en.wikipedia.org/wiki/Flexible_array_member), but this is not legal in Standard C++. – user4581301 Mar 02 '20 at 17:42
  • bigmooky struggling with implementation is normal and the main frustration of programming (in my unprofessional opinion). There's no shame in it! I would say just think how you perform a task as a human, or think about a task, and look at that in a logical breakdown. – FShrike Mar 02 '20 at 21:43
  • @user4581301: You can also have (non-local) variables of type `T[]`, and you can have pointers or references to arrays of unknown bound: `T(*)[]`. But those are, by comparison, negligibly rare. – Davis Herring Mar 03 '20 at 03:15

0 Answers0