Defining function error

I'm getting some errors defining some functions here. I'm prohibited from changing my header files unfortunately :(

here are the four errors:
Book.cpp:20: error: prototype for ‘Book::Book()’ does not match any in class ‘Book’
Book.hpp:15: error: candidates are: Book::Book(const Book&)
Book.hpp:28: error: Book::Book(std::string, std::string, std::string)
Book.cpp: In member function ‘int Book::getCheckOutLength()’:

header:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  //Book.hpp
#ifndef BOOK_HPP
#define BOOK_HPP
#include <string>

class Patron;

// These three locations are mutually exclusive, but note that
// a Book can be on request for a Patron while being checked
// out to another Patron.  In that case the Book's location is 
// CHECKED_OUT, and when it is returned, it's location will
// become ON_HOLD_SHELF
enum Locale { ON_SHELF, ON_HOLD_SHELF, CHECKED_OUT };

class Book {

private:
	std::string idCode;
	std::string title;
	std::string author;
	Locale location;
	Patron* checkedOutBy;
	Patron* requestedBy;
	int dateCheckedOut;

public:
	static const int CHECK_OUT_LENGTH = 21;
	Book(std::string idc, std::string t, std::string a);
	int getCheckOutLength();
	std::string getIdCode();
	std::string getTitle();
	std::string getAuthor();
	Locale getLocation();
	void setLocation(Locale);
	Patron* getCheckedOutBy();
	void setCheckedOutBy(Patron*);
	Patron* getRequestedBy();
	void setRequestedBy(Patron*);
	int getDateCheckedOut();
	void setDateCheckedOut(int);
};
#endif


and the parts of my cpp that have the issues:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include "Book.hpp"
#include "Patron.hpp"
#include <string>
using namespace std;



/******************************************************************************
** Description: Default constructor.
*******************************************************************************/
Book::Book() {}

/******************************************************************************
** Description: constructor
*******************************************************************************/
Book::Book(string idc, string t, string a) {
	idCode = idc;
	title = t;
	author = a;
	location = ON_SHELF;
	checkedOutBy = NULL;
	requestedBy = NULL;
}

/******************************************************************************
** Description: get and add functions
*******************************************************************************/
int Book::getCheckOutLength() {
	return (getCurrentDate() - dateCheckedOut);
}



thanks for your help!


EDIT: ahh wait a second, i should've just added
 
Book::Book(std::string idc, std::string t, std::string a)


for that third error i think. still confused about the other three :(
Last edited on
Look at your errors starting from the top:
Book.cpp:20: error: prototype for ‘Book::Book()’ does not match any in class ‘Book’

Here you implemented a Book constructor with no arguments, but in your class definition there is no Book constructor with no arguments. If you can't modify the include file then you need to delete this implementation.

Book.hpp:15: error: candidates are: Book::Book(const Book&)
Book.hpp:28: error: Book::Book(std::string, std::string, std::string)

These are just telling you more about the above error. If you had more possible constructors there would be more lines like this one.

Book.cpp: In member function ‘int Book::getCheckOutLength()’:

There should be more to this error message. It should give you an actual error description and a line number.

Always start with the first error, fix it, then recompile. Many times fixing one problem will fix several errors.
Topic archived. No new replies allowed.