首页 文章

请求成员,非类型

提问于
浏览
-1

我的代码中出现了大量错误,这一切都归结为以下几点:

Library.cpp:89:错误:'((Library *)this)中成员'getLocation'的请求 - > Library :: holdings.std :: vector <_Tp,_Alloc> :: operator [] [with _Tp = Book * ,_Alloc = std :: allocator]((long unsigned int)bookOnFile))',它是非类型'Book *'

我对如何编写以下内容感到困惑:

Patron* matchPatron = &members[patronOnFile];
    if (PatronIDMatch == true && bookIDMatch == true) {
        if (holdings[bookOnFile].getLocation() == ON_SHELF) {
            holdings[bookOnFile].setCheckedOutBy(matchPatron);
            holdings[bookOnFile].setLocation(CHECKED_OUT);
            holdings[bookOnFile].setDateCheckedOut(currentDate);
            members[patronOnFile].setCheckedOutBooks(&holdings[bookOnFile]);
            cout << members[patronOnFile].getName() << " check out successful"
                << holdings[bookOnFile].getTitle() << ".";

(我有这么多行的错误代码,这个只适用于getLocation行 . )

我的 Headers 如下:

//Library.hpp
#ifndef LIBRARY_HPP
#define LIBRARY_HPP
#include <string>
#include <vector>
#include "Patron.hpp"

class Library {

private:
    std::vector<Book*> holdings;
    std::vector<Patron*> members;
    int currentDate;

public:
    Library();
    void addBook(Book*);
    void addPatron(Patron*);
    std::string checkOutBook(std::string pID, std::string bID);
    std::string returnBook(std::string bID);
    std::string requestBook(std::string pID, std::string bID);
    std::string payFine(std::string pID, double payment);
    void incrementCurrentDate();
    Patron* getPatron(std::string pID);
    Book* getBook(std::string bID);
};
#endif

我在这里写错了代码吗?我该怎么写呢?如果需要,我可以提供我的整个程序 .

编辑:

Patron* matchPatron = &members[patronOnFile];

1 回答

  • 1

    你有一个 Book* 的向量,它们是指针,但你在调用 holdings[bookOnFile].getLocation() 时使用点表示法 . 其他方法调用也是如此 . 尝试替换为 holdings[bookOnFile]->getLocation() 等 .

相关问题