Thursday, 15 March 2012

c++ - Hi, I very confused on why I am getting a compilation error mainly: "Library.cc:(.text+0x27): undefined reference to `PatronArray::PatronArray()'" -



c++ - Hi, I very confused on why I am getting a compilation error mainly: "Library.cc:(.text+0x27): undefined reference to `PatronArray::PatronArray()'" -

this library.h file, before library used dirty work: in term of manipulating arrays , stuff, trying create library middle man invoke phone call has array manipulations. problem trying have 1 instance of patron array, hold patrons in library.

#ifndef library_h #define library_h #include <string> #include "types.h" #include "book.h" #include "patron.h" #include "patronarray.h" //class patronarray class library { public: library(); ~library(); void init(); int addbook(book*); int addpatron(patron*); int rempatron(int); int findbook(int, book**, int*); int findpatron(string, string, patron**, int*); int getmaxcollindex(); int getmaxpatronsindex(); book* getbook(int); patron* getpatron(int); private: book* collection[max_coll_size]; patronarray* patrons; int maxcollindex; int maxpatronsindex; }; #endif

this library.cc file

#include "library.h" library::library() : maxcollindex(0) { patrons = new patronarray; (int i=0; i<max_coll_size; ++i) { collection[i] = 0; } } library::~library() { delete patrons; (int i=0; i<maxcollindex; ++i) delete collection[i]; } int library::getmaxcollindex() { homecoming maxcollindex; } int library::getmaxpatronsindex() { homecoming patrons->getmaxpatronsindex(); } book* library::getbook(int index) { if (index < 0 || index >= maxcollindex) homecoming 0; homecoming collection[index]; } patron* library::getpatron(int index) { homecoming patrons->getpatron(index); } void library::init() { book* newbook; patron* newpatron; newbook = new book("ender's game", "orson scott card", 1985); addbook(newbook); newbook = new book("dune", "frank herbert", 1965); newbook->setstatus(lost); addbook(newbook); newbook = new book("foundation", "isaac asimov", 1951); addbook(newbook); newbook = new book("hitch hiker's guide galaxy", "douglas adams", 1979); addbook(newbook); newpatron = new patron("jack", "shephard"); addpatron(newpatron); } int library::addbook(book* book) { if (maxcollindex >= max_coll_size - 1) { homecoming c_nok; } collection[maxcollindex++] = book; homecoming c_ok; } int library::addpatron(patron* patron) { // lbrary middle ma invokesthe calls //return patronarray->addpatron(patron); homecoming patrons->addpatron(patron); } int library::rempatron(int index) { homecoming patrons->rempatron(index); } int library::findpatron(string fn, string ln, patron** patron, int* index) { homecoming patrons->findpatron(fn,ln,patron,index); } int library::findbook(int id, book** book, int* index) { (int i=0; i<maxcollindex; ++i) { if (collection[i] == 0) continue; if (collection[i]->getid() == id) { *book = collection[i]; *index = i; homecoming c_ok; } } *book = 0; *index = -1; homecoming c_nok; }

this patronarray.h holds patrons registered within library.

#ifndef patronarray_h #define patronarray_h #include "patron.h" #include "book.h" #include "types.h" //class patron; class patronarray { public: patronarray(); ~patronarray(); int addpatron(patron*); int rempatron(int); int findpatron(string, string, patron**, int*); int getmaxpatronsindex(); patron* getpatron(int); private: patron* patrons[max_coll_size]; int maxpatronsindex; }; #endif

and patronarray.cc file , please, know there improve way of doing doing templating dont understand yet plus way helps me understand whole object oriented style.

#include<iostream> #include<string> #include "patronarray.h" /* * default constructor: recheck later */ patronarray::patronarray() :maxpatronsindex(0) { (int = 0; < max_coll_size; ++i) { patrons[i] = 0; } } /* * destructor: recheck later */ patronarray::~patronarray() { (int = 0; < maxpatronsindex; ++i) delete patrons[i]; } //get maxindex int patronarray::getmaxpatronsindex() { homecoming maxpatronsindex; } /* * adds given patron given patrons array */ int patronarray::addpatron(patron* patron) { if (maxpatronsindex >= max_coll_size - 1) { homecoming c_nok; } patrons[maxpatronsindex++] = patron; homecoming c_ok; } /* * used removing patron in patrons array */ int patronarray::rempatron(int index) { if (index < 0 || index >= maxpatronsindex) homecoming c_nok; delete patrons[index]; patrons[index] = 0; homecoming c_ok; } /* * searches patron; if found, sets contents of sec * parameter patron pointer, sets contents of 3rd parameter * index in collection, , returns c_ok; if not found, sets * contents of sec parameter zero, theird -1, , returns c_nok */ int patronarray::findpatron( string fn, string ln, patron** patron, int* index) { (int = 0; < maxpatronsindex; ++i) { if (patrons[i] == 0) continue; if (patrons[i]->getfname() == fn && patrons[i]->getlname() == ln) { *patron = patrons[i]; *index = i; homecoming c_ok; } } *patron = 0; *index = -1; homecoming c_nok; } patron* patronarray::getpatron(int index) { if (index < 0 || index >= maxpatronsindex) homecoming 0; homecoming patrons[index]; }

i forgot link patronarray.cc library.cc in makefile, give thanks jack!

c++ oop dynamic-allocation

No comments:

Post a Comment