如何从函数返回结构

我正在学习c ++,我的项目是关于队列的。

我有:

struct dough {
    string code;
    int stirringTime;
};

通常,在我的任务中,我们使用int而不是struct。这就是为什么我的删除功能有问题:

使用int:

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

如果我这样做:

struct delQ(Queue &Q) // => what do i return?
fcliuhongpeng 回答:如何从函数返回结构

您用struct定义的类型不是struct,而是dough

因此,如果您习惯使用int,但想使用新结构,只需将int替换为dough

dough delQ(Queue &Q)  {
    dough retval;   // I don't know how you initialize your struct
    ....
    return retval;  
}
本文链接:https://www.f2er.com/3149995.html

大家都在问