简体   繁体   中英

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?

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;  
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM