1

我有以下课程:

#include <string>
#include <cstdlib>

using namespace std;

class Locker{


public:

int lockerId;

string renterName;

double monthlyRent;

// The variable is true when the locker is a vip locker
//if the locker is a regular locker then this variable is set to false

bool isVip;

bool isRentOverdue;

Locker(){};

Locker(int id, string name, double rent, bool vip=0, bool overdue=0);

bool operator==(Locker const &other);
 };

编辑:储物柜节点类

class LockerNode{
public:

Locker objLocker;
LockerNode *next;


LockerNode(){
    next=0;
};

LockerNode(Locker e, LockerNode *ptr=0){
    objLocker=e;
    next=ptr;
}
  };

和实施:

#include <sstream>
#include "Locker.h"

#include <iostream>

 using namespace std;

 Locker::Locker(int id, string name, double rent, bool vip, bool overdue){
lockerId=id; renterName=name; monthlyRent=rent; isVip=vip; isRentOverdue=overdue;
 }

 bool Locker::operator==(Locker const &other){
if(lockerId==other.lockerId && renterName==other.renterName && monthlyRent==other.monthlyRent && isVip==other.isVip && isRentOverdue==other.isRentOverdue)
    return true;
else return false;
 }

我在函数中有以下代码,试图跟踪链表中对象的数量,并根据它们的数量和属性对它们执行一些操作。我传入的e是一个新创建的对象。如果一个对象的属性 vip = true,我需要将它放在其他非 vip 对象的前面,除非已经有一个 vip 对象,在这种情况下它就在它后面。因此,以下代码:

int count = 0;
LockerNode *p = head;

for(;p!=0;count++, p=p->next) {

    if(count == 1) {
        if (e.isVip) {
            if(p->isVip) // !!!!!!!!!Issue here!!!!!!!!!!
        }

    }

我检查了参数fine以确定它是否是vip。但是,我不确定如何检查我在列表中的当前元素是否相同。我在有问题的线路上的上述努力没有奏效。我对语法有点困惑。谁能帮我吗?

谢谢!

4

1 回答 1

1

你的储物柜节点类在哪里?问题可能在那里...

好的尝试替换这个:

 if(p->isVip) // !!!!!!!!!Issue here!!!!!!!!!!

和:

if (p->objLocker.isVip) {//true/false for this node

p 是一个访问他的成员的指针是->,但 objlocker 不是一个访问他的成员的指针是一个“。”

于 2013-06-03T21:43:22.040 回答