Undefined Reference Error in class
Dec 1, 2016 at 9:49am UTC
Why am I getting this error?
When creating a class object array, similar to this it has worked before. Is it because of the loop it is in? or something else?
How would i correct this?
The reason I am using an array is because there is a comparison of two objects later on.
useDatabase.cpp:(.text+0x2d5): undefined reference to `Books::Books()'
[Error] ld returned 1 exit status
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
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Books
{
private :
string Title;
string Publisher;
int Year;
vector<string> Author;
int NumAuthors;
public :
//empty constructor
Books();
Books(const string& title, const string& publisher, int yearOfPublication, string*authors, int numAuthors);
};
//Book Constructor
Books::Books(const string& title, const string& publisher, int yearOfPublication, string* authors, int numAuthors)
{
Title = title;
Publisher = publisher;
Year = yearOfPublication;
Author = vector<string>();
for (int i =0; i<numAuthors; i++)
{
Author.push_back(authors[i]);
}
NumAuthors = numAuthors;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include<iostream>
#include<string>
#include<fstream>
#include "Books.cpp"
int const MAX = 10;
using namespace std;
int main()
{
Books arrayBooks[MAX] = Books();
//THIS IS WHERE THE ERROR IS
arrayBooks[k] = Books(title,publisher,yOp, authors, numAuth);
cout << arrayBooks[k];
}
Last edited on Dec 1, 2016 at 7:32pm UTC
Dec 1, 2016 at 9:55am UTC
You have forgot to define the Books default constructor.
Dec 1, 2016 at 7:31pm UTC
silly me. Thank you
Topic archived. No new replies allowed.