我得到了
表达式必须是可修改的左值
在
rear->getNextNode() = &node;
这是代码:
using namespace std;
#include<iostream>
#include<string>
class Node
{
string name;
Node* next;
int arrivedTime;
int runningTime;
char state='R';
public:
Node(char* name,int arrivedTime,int runningTime):name(name),arrivedTime(arrivedTime),runningTime(runningTime){}
void printState()
{
cout << "name=" << name << " " << endl;
}
void execute()
{
runningTime--;
printState();
}
bool whetherArrive()
{
if (arrivedTime > 0)
{
return false;
}
else
{
return true;
}
}
void downArrivedTime()
{
arrivedTime--;
}
Node* getNextNode()
{
return next;
}
};
class Queue
{
public:
Node* head;
Node* rear;
Node* p;
void insert(Node &node)
{
if (head == NULL)
{
head = &node;
rear = &node;
p = &node;
}
else
{
rear->getNextNode() = &node; //here hint Expression must be a modifiable lvalue
}
}
};
int main()
{
cout << "input: process-count" << endl;
int processCount;
cin >> processCount;
for (int i = 0; i < processCount; i++)
{
cout << "input:process-name arrivedTime runningTime" << endl;
char name[20];
int arrivedTime;
int runningTime;
cin >> name >> arrivedTime >> runningTime;
Node node(name, arrivedTime, runningTime);
}
}
rear->getNextNode()
返回指向Node
的指针,然后设置点&node
。这有什么不对?
答案 0 :(得分:1)
在错误中,要进行编译:
rear->getNextNode() = &node;
getNextNode()
必须返回左值,因此您需要将singature修改为:
Node*& getNextNode()
^