"Undefined Reference" Error! Help Plz
Would someone help me understand why I keep getting the error:
"In function main: [linker error] undefined reference to readBook(BookData)"
I have spend hours trying to fix it, but no luck :/
Thanks in advance
main.cpp :
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
#include "BookData.h"
// FUNCTION PROTOTYPES:
void bookInfo(BookData);
void readBook(BookData& book1);
int main(){
BookData book1, book2;
cout << "\nEnter the data for the first book:\n";
readBook(book1);
cout << "\nEnter the data for the second book:\n";
readBook(book2);
cout << "\nDisplay the data for the first book:\n";
bookInfo(book1);
cout << "\nDisplay the data for the second book:\n";
bookInfo(book2);
system("pause");
return 0;
}
void bookInfo(BookData book)
{
string temp;
cout << left;
cout << " " << setw(22) << "ISBN:" << book.getIsbn() << endl;
cout << " " << setw(22) << "Title:" << book.getTitle() << endl;
cout << " " << setw(22) << "Author:" << book.getAuthor() << endl;
cout << " " << setw(22) << "Publisher:" << book.getPub() << endl;
cout << " " << setw(22) << "Date Added:" << book.getDateAdded() << endl;
cout << " " << setw(22) << "Quantity-On-Hand:" << book.getQty() << endl;
cout << " " << setw(22) << "Wholesale Cost:" << "$" << fixed << setprecision(2) << book.getWholeSale() << endl;
cout << " " << setw(22) << "Retail Price:" << "$" << book.getRetail() << endl;
temp = book.isEmpty()?"yes":"No";
cout << " " << setw(22) << "Empty?" << temp << endl;
}
void readBook(BookData& book1)
{
string tempS;
int tempI;
double tempD;
cout << "Enter the Title: ";
cin >> tempS;
book1.setTitle(tempS);
cout << "Enter the ISBN: ";
cin >> tempS;
book1.setIsbn(tempS);
cout << "Enter the Author: ";
cin >> tempS;
book1.setAuthor(tempS);
cout << "Enter the Publisher: ";
cin >> tempS;
book1.setPub(tempS);
cout << "Enter Date Added: " ;
cin >> tempS;
book1.setDateAdded(tempS);
cout << "Enter Quantity on Hand: ";
cin >> tempI;
book1.setQty(tempI);
cout << "Enter Wholsale Price: " ;
cin >> tempD;
book1.setWholesale(tempD);
cout << "Enter Retail Price: " ;
cin >> tempD;
book1.setRetail(tempD);
cout << "Enter 1 to insert the book or 0 to remove: ";
cin >> tempI;
while (tempI > 1 || tempI < 0)
{
cout << "Wrong entry. Try again: ";
cin >> tempI;
}
if (tempI == 0)
book1.insertBook();
else
book1.removeBook();
}
|
BookData.cpp :
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
#include <string>
class BookData
{
private:
string bookTitle;
string isbn;
string author;
string publisher;
string dateAdded;
int qtyOnHand;
double wholesale;
double retail;
bool empty;
public:
BookData();
void setTitle(string object);
void setIsbn(string code);
void setAuthor(string auth);
void setPub(string pub);
void setDateAdded(string dateAdd);
void setQty(int quant);
void setWholesale(double price);
void setRetail(double temp);
bool isEmpty();
void insertBook();
void removeBook();
string getTitle();
string getIsbn();
string getAuthor();
string getPub();
string getDateAdded();
int getQty();
double getWholeSale();
double getRetail();
};
BookData::BookData()//Default Constructor
{
qtyOnHand = 0;
wholesale = 0;
retail = 0;
empty = true;
bookTitle = isbn = author = publisher = dateAdded = "";
}
void BookData::setTitle(string object)
{
bookTitle = object;
}
void BookData::setIsbn(string code)
{
isbn = code;
}
void BookData::setAuthor(string auth)
{
author = auth;
}
void BookData::setPub(string pub)
{
publisher = pub;
}
void BookData::setDateAdded(string dateAdd)
{
dateAdded = dateAdd;
}
void BookData::setQty(int quant)
{
qtyOnHand = quant;
}
void BookData::setWholesale(double price)
{
wholesale = price;
}
void BookData::setRetail(double temp){
retail = temp;
}
bool BookData::isEmpty(){
return empty;
}
void BookData::insertBook(){
empty = false;
}
void BookData::removeBook(){
empty = true;
}
string BookData::getTitle(){
return bookTitle;
}
string BookData::getIsbn(){
return isbn;
}
string BookData::getAuthor(){
return author;
}
string BookData::getPub(){
return publisher;
}
string BookData::getDateAdded(){
return dateAdded;
}
int BookData::getQty(){
return qtyOnHand;
}
double BookData::getWholeSale(){
return wholesale;
}
double BookData::getRetail(){
return retail;
}
|
DataBook.h :
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
|
#ifndef BOOKDATA_H
#define BOOKDATA_H
#include <string>
class BookData
{
private:
string bookTitle;
string isbn;
string author;
string publisher;
string dateAdded;
int qtyOnHand;
double wholesale;
double retail;
bool empty;
public:
BookData();
void setTitle(string object);
void setIsbn(string code);
void setAuthor(string auth);
void setPub(string pub);
void setDateAdded(string dateAdd);
void setQty(int quant);
void setWholesale(double price);
void setRetail(double temp);
bool isEmpty();
void insertBook();
void removeBook();
string getTitle();
string getIsbn();
string getAuthor();
string getPub();
string getDateAdded();
int getQty();
double getWholeSale();
double getRetail();
};
#endif
|
There is no definition of function readBook(BookData) in your program. Check the declaration and the definition of this name.
Last edited on
bookInfo(ReadBook), this needs to be by reference.
Topic archived. No new replies allowed.