Search code examples
c++functionstructreturn-type

How to return a struct from a function


I'm learning c++ and my project is about queues.

I have :

struct dough {
    string code;
    int stirringTime;
};

Usually in my tasks, we use int and not struct. That is why I have problems with my delete function:

Using int :

int delQ(Queue &Q) // => return int

If I make:

struct delQ(Queue &Q) // => what do i return?

Solution

  • The type that you have defined with struct is not struct but dough.

    So if you are use to work with int, but want to work with your new structure instead, just replace int with dough:

    dough delQ(Queue &Q)  {
        dough retval;   // I don't know how you initialize your struct
        ....
        return retval;  
    }