I got
Expression must be a modifiable lvalue
in
rear->getNextNode() = &node;
Here is code:
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()
return a pointer to Node
, and then set the point &node
. What's wrong here?