修改结构的变量数据

Modifying Structure's variable Data

用户自定义Queue的前台函数

template<class Type>
Type queueType<Type>::front()
{
    if(!isEmptyQueue());
    return list[queueFront]; 
}

int main()
{
    struct process
    {
        int burst;
    }pro;

    int tq=2;
    pro.burst=10;
    Queue<process> RR;  
    RR.enQueue(pro);  
    RR.front().burst=RR.front().burst - tq; 
}

当我尝试 运行 这一行时:

RR.front().burst=RR.front().burst - tq;

它给出了以下错误:

using temporary as lvalue [-fpremissive]

此错误背后的原因是什么?还有其他方法可以执行此设置吗?请给我一个更好的解决方案来执行此操作。

front() 应该 return Type&。否则要 returned 的值在实际 returned.

之前 copied
template<class Type>
Type& queueType<Type>::front() { ... }

如果您希望能够使用 front() 修改第一个元素,则需要 return 对它的引用,而不是副本:

Type & front();
     ^

你还需要在 if(!isEmptyQueue()) 之后删除虚假的 ;,如果它是空的,可能会抛出异常。