4

I'm trying to run this program in another file(main.cc) but I get an error on this class, where this is the error.

ERROR

./Library.h:15:24: error: expected ')'
    Library(Book[] &book, int &currentNumOfBooks);
                   ^
./Library.h:15:16: note: to match this '('
        Library(Book[] &book, int &currentNumOfBooks);
               ^

CODE SOURCE:

class Library{

public:

    Book booksLibrary[MAX_ARR_SIZE];
    int currentNumOfBooksLibrary;
    Library();
    Library(Book[] &book, int &currentNumOfBooks);
    void addBook(Book &book);
    void print();
private:
}:
  • 6
    Sounds like you could use a [good C++ book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). This is not proper syntax for C++. – NathanOliver Sep 19 '18 at 14:19
  • 2
    One cannot have array of references. – Algirdas Preidžius Sep 19 '18 at 14:19
  • 3
    `std::vector`, `std::array` might help. – Jarod42 Sep 19 '18 at 14:20
  • 1
    If you are trying to take an array by reference, see [this question](https://stackoverflow.com/questions/10007986/c-pass-an-array-by-reference). – François Andrieux Sep 19 '18 at 14:21
  • Wow I can't belive I had wrong syntax, and I see the now , so you cant pass arrays by reference? – alroithmhelp Sep 19 '18 at 14:22
  • 3
    To quote a wise master: You must unlearn what you have learned. Learning a new language usually requires you to basically start from scratch, there's seldom much you can bring with you from your old language (even if some syntax is still similar, there might be semantic differences). – Some programmer dude Sep 19 '18 at 14:23
  • @alroithmhelp You can but you should probably be using a `std::vector` instead of arrays to make life easy. – NathanOliver Sep 19 '18 at 14:25
  • You can degenerate arrays into pointers and use pointer arithmetics, but the better solution here is to use a container class, like those that Jarod42 mentioned. – Aziuth Sep 19 '18 at 14:25
  • 1
    Oh and you *can* pass a reference to an array, but it's seldom really needed. For completeness: `Book (&books)[MAX_ARRAY_SIZE]`. – Some programmer dude Sep 19 '18 at 14:28

0 Answers0