0

I have an error when I declare the non-member function 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;
    }
  }

compiler says name papers and books was not declared in this scope. I have tried several thing like making the function friend but then in the main it says that class Biblioagraphy has no member called listOverview();

This is my header:

#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

2 Answers2

1

When you are going to define the function that are part of your class. You need to do it explicitly.

instead of

void listOverview()

it should be

void Bibliography::listOverview()
Tarik Neaj
  • 548
  • 2
  • 10
  • thank you, this solved it, i was focused on the working of non-member functions i just had to make it member. you solved a few hours of work :P – Noel Peña Blanco Jan 07 '16 at 10:58
1

If listofOverview is a free function, there's no books declared inside or passed by argument (and NO, you don't want to use global variables).

If you consider it as a class member, you should write void Bibliography::listOfOverview() but's a class member not a free function.

Jepessen
  • 9,377
  • 11
  • 64
  • 111