gpt4 book ai didi

c++ - 名称、论文、书籍未在此范围内声明非成员函数 C++

转载 作者:行者123 更新时间:2023-11-28 02:13:57 28 4
gpt4 key购买 nike

我在声明非成员函数listOverview()时出错;

  void listOverview()
{

std::cout << "Overview of books of " << name << std::endl;
for (auto p : books)
{
std::cout << p.toString() << std::endl;
}
std::cout << "Overview of papers of " << name << std::endl;
for (auto p : papers)
{
std::cout << p.toString() << std::endl;
}
}

编译器说名称文件和书籍未在此范围内声明。我已经尝试了几种方法,比如使函数成为 friend ,但主要是它说 Biblioagraphy 类没有名为 listOverview() 的成员;

这是我的标题:

#ifndef BIBLIOGRAPHY_H
#define BIBLIOGRAPHY_H
#include <string>
#include <vector>


class Book;
class Paper;

class Bibliography
{
public:
Bibliography(const std::string & aName);

void addBook(const Book * newBook);
void addPaper(const Paper *newPaper);
int giveNrOfBooks() const {return books.size();}
int giveNrOfPapers() const {return papers.size();}
void listOverview();
// std::vector<std::shared_ptr<Publication>> givePubWithIFHigherThan(float value) const;
// void replaceIFofJournalsMatching(const std::regex journal, float newIF);
private:
const std::string name;
std::vector<const Book *> books;
std::vector<const Paper *> papers;

};

#endif // BIBLIOGRAPHY_H

最佳答案

当您要定义属于您的类的函数时。您需要明确地执行此操作。

代替

void listOverview()

应该是

void Bibliography::listOverview()

关于c++ - 名称、论文、书籍未在此范围内声明非成员函数 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34653300/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com