c++ - "Undefined symbols for Architecture x86_64 " no templates used, possible syntax error -
c++ - "Undefined symbols for Architecture x86_64 " no templates used, possible syntax error -
i know mutual question, please bear me. understand seeing past questions:
i not using templates, " template class treenode; " before each utilize of template, assuming problem similar, related syntax, or basic. if answered edit question more people benefit it.so have utilize these code operations in main.cpp carry out operations- e.g. utilize deleteitem, retrieve 10 , print whether found, etc.
the code follows:
//unsortedtype.h #ifndef unsortedtype_h_included #define unsortedtype_h_included #include "itemtype.h" class unsortedtype { public: unsortedtype(); bool isfull() const; int lengthis() const; void retrieveitem(itemtype&item, bool&found); void insertitem(itemtype item); void deleteitem(itemtype item); void resetlist(); void getnextitem(itemtype& item); void printlist(); private: int length; itemtype info[max_items]; int currentpos; }; #endif // unsortedtype_h_included
//fileno2
//unsortedtyoe.cpp #ifndef unsortedtype_cpp_included #define unsortedtype_cpp_included #include "unsortedtype.h" unsortedtype::unsortedtype() { length = 0; currentpos = -1; } bool unsortedtype::isfull() const { homecoming (length == max_items); } int unsortedtype::lengthis() const { homecoming length; } void unsortedtype::retrieveitem(itemtype &item, bool &found){ int location = 0; bool moretosearch = (location < length); found = false; while (moretosearch && !found){ switch (item.comparedto(info[location])) { case less: case greater: location++; moretosearch = (location < length); break; case equal: found = true; } } } void unsortedtype::insertitem(itemtype item) { info[length] = item; length++; } void unsortedtype::deleteitem(itemtype item){ int location = 0; while (item.comparedto(info[location]) != equal){ location++; info[location] = info[length - 1]; length++; } } void unsortedtype::resetlist(){ currentpos = -1; } void unsortedtype::getnextitem(itemtype &item){ currentpos++; item = info[currentpos]; } void unsortedtype::printlist(){ itemtype it; (int = 1; <= length; i++){ getnextitem(it); it.print(); cout<<""; } resetlist(); cout<<endl; } #endif // unsortedtype_cpp_included
//fileno3
//itemtype.h #ifndef itemtype_h_included #define itemtype_h_included #include <iostream> using namespace std; const int max_items = 5; enum relationtype{less, greater, equal}; class itemtype{ public: itemtype(); relationtype comparedto(itemtype) const; void print() const; void initialize(int number); private: int value; } ; #endif // itemtype_h_included
fileno4
//itemtype.cpp #ifndef itemtype_cpp #define itemtype_cpp #include "itemtype.h" itemtype::itemtype(){ value = 0; } relationtype itemtype::comparedto(itemtype otheritem) const { if (value<otheritem.value) homecoming less; else if (value > otheritem.value) homecoming greater; else homecoming equal; } void itemtype::initialize(int number){ value = number; } void itemtype::print() const { cout << value << ""; } #endif // itemtype_cpp
main
#include <iostream> #include "itemtype.h" #include "unsortedtype.h" using namespace std; int main() { unsortedtype ustype1; cout << ustype1.lengthis() << endl; /* //insertitem ustype1.insertitem(5); ustype1.insertitem(7); ustype1.insertitem(6); ustype1.insertitem(9); ustype1.printlist(); ustype1.insertitem(1); ustype1.printlist(); //retreiveitem bool found; ustype1.retrieveitem(4, found); cout << found << endl; ustype1.retrieveitem(5, found); cout << found << endl; ustype1.retrieveitem(9, found); cout << found << endl; ustype1.retrieveitem(10, found); cout << found << endl; //isfull cout << ustype1.isfull() << endl; ustype1.deleteitem(5); cout << ustype1.isfull() << endl; //deleteitem ustype1.deleteitem(1); ustype1.printlist(); ustype1.deleteitem(6); ustype1.printlist(); */ cout << "hello world!" << endl; homecoming 0; }
my first problem this, when take out commented lines in main, , islength, this: http://i.imgur.com/xl8avs2.png?1
i think might basic error, , if coudl tell me how resolve grateful.
pps> beingness little lazy, when utilize commented out code in main, error, can tell me how insert integers functions itemtype?
http://i.imgur.com/e4mpbi5.png?1
edit: image 1:
-------------- build: debug in unsortedlist (compiler: gnu gcc compiler)--------------- g++ -o bin/debug/unsortedlist obj/debug/main.o obj/debug/unsortedtype.o -lstdc++ undefined symbols architecture x86_64: "itemtype::itemtype()", referenced from: unsortedtype::unsortedtype()in unsortedtype.o unsortedtype::unsortedtype()in unsortedtype.o unsortedtype::printlist() in unsortedtype.o "itemtype::comparedto(itemtype) const", referenced from: unsortedtype::deleteitem(itemtype) in unsortedtype.o unsortedtype::retrieveitem(itemtype&, bool&) in unsortedtype.o "itemtype::print() const", referenced from: unsortedtype::printlist() in unsortedtype.o ld: symbol(s) not found architecture x86_64 collect2: ld returned 1 exit status process terminated status 1 (0 minute(s), 0 second(s)) 0 error(s), 0 warning(s) (0 minute(s), 0 second(s))
you should specify itemtype.o on command line following.
g++ -o bin/debug/unsortedlist obj/debug/main.o obj/debug/unsortedtype.o obj/debug/itemtype.o
c++
Comments
Post a Comment