我已经声明并实现了两个类,Library
和Book
。 Library
有一个私有成员Book** books
。这个指向指针的指针用于存储指向Book
对象的指针。我还在Library
类中重载了+=
运算符,如下所示:
Library& Library::operator+=(Book* addThisBook){
bool added = false;
int index = 0;
if(isFull()){
cout << "Library is full!" << endl;
}else{
//add book in first available space
while(!added && index<librarySize){
if(books[index] == nullptr){
books[index] = addThisBook;
added = true;
}
index++;
}
numBooks++;
}
return *this;
}
我的问题与if语句中的条件有关;是否允许将指向自定义类的指针与nullptr
进行比较?
books[index]
)确实初始化为nullptr
。 - dureuill