![]() |
| ||
| Error in c++ program I have design two program and both have errors on it. the first is supposed to handle queue on integer, double, string and date. I have done for integer and double. When I compile it there was error on it. If you can just help me debug it and i will complete the string and date myself. i have to submit this by Thursday. below is the code for it: //listnd.hThank you for your help. |
| ||
| Re: Error in c++ program. urgent >If you can just help me debug it I'll help, but I'm not going to do it for you. Debugging is what the majority of programming is, so if I did it for you then you would learn nothing. As it is, you didn't specify what the error was in the first program, and I have better things to do than figure out what you think is wrong with it then tell you so that you can claim m4d debugging sk1llz. :rolleyes: >qsort (list, 10, sizeof(int), compare); //error You can't call a function in a class definition. >if (bsearch(&key,list,10,sizeof(int),compare)) //error Is the error "Unrecognized function" or something similar? Tell us what the errors are! And include <cstdlib> because that's where qsort and bsearch are declared. |
| ||
| Re: Error in c++ program. urgent For the first problem that is about queues. I have debug it and when I compile the program there is no error or warning but when i build it it says 3 errors. Below is the modified code and the errors Code: //listnd.h Error: 1. T2.OBJ : error LNK2001: unresolved external symbol "public: bool __thiscall List<int>::removeFromFront(int &)" (?removeFromFront@?$List@H@@QAE_NAAH@Z) 2. T2.OBJ : error LNK2001: unresolved external symbol "public: bool __thiscall List<double>::removeFromFront(double &)" (?removeFromFront@?$List@N@@QAE_NAAN@Z) 3. Debug/T2.exe : fatal error LNK1120: 2 unresolved externals Honestly speaking i don't have a clue what this means. I tried going through the whole program again and again. Checking through to see what the problem and i can't find it. ( note: T2 is the name of the program. T2.cpp ). Anyone can explain to me on how to handle this? :confused: :mad: |
| ||
| Re: Error in c++ program. urgent >Honestly speaking i don't have a clue what this means. It means you didn't define removeFromFront for List. You declared the member function, but because it was never defined, the linker complains when it tries to find it. |
| ||
| Re: Error in c++ program Midnight Skulke: Just a couple of FYIs when posting on the forums here: Firstly, I removed the word "urgent" from your thread title. You post is no more urgent than anyone else's here, and it's rude to assume that it is, just because you have a deadline. Second, we should enforce this for everyone, but it's especially important when you're posting such long code snippets. Please embed your code in Vbulletin code tags. It's just like HTML; just take your code, and put a [ code] tag at the beginning, and a [ /code] tag at the end. (Remove the space after each [ in the tag-- that's the only way I could get the forum to display the tags. |
| ||
| Re: Error in c++ program Hey thanks for the tips. The second problem is the quicksort and bsearch problem. I tried to declare but i'm not sure how to do it. I tried but everytime I run it, it keep saying undeclared idetifier. So can anyone tell me how to solve this: [ code] #include <iostream.h> #include <algorithm> #include <stdlib.h> //class quicksort class qsort { public: int compare(const void*, const void*); public: int list; int element; //int compare2; }; //class bsearch class bsearch { public: int compare(const void*, const void*); public: int list; int element; int key; }; int main() { int list[10] = {9,5,2,8,1,7,3,6,4,0}; int key = 3; //display unsorted list for (int element = 0; element <= 9; element++) { cout << list[element] << " "; } cout << endl; qsort (list, 10, sizeof(int), compare1); //error //display sorted list for (element = 0; element <= 9; element++) { cout << list[element] << " "; } //displays whether the number in the array or not if (bsearch(&key,list,10,sizeof(int), compare2)) //error { cout<<key<<" is in the array"<<endl; //number in array } else { cout << key <<" is NOT in the array2" <<endl; //number not in array } return 0; } int compare3(const void* a_PTR, const void* b_PTR) { return *((int*)a_PTR) - *((int*)b_PTR); }[ /code] As you can see the code above, where the remark error is it says compare1 and compare2 undeclare identifier. I tried identifying at private and public as int compare1 and int compare2 but it still gives this error. can you give me a example along explanation Sorry but i'm really weak in C++. |
| ||
| Re: Error in c++ program >I tried to declare but i'm not sure how to do it. They're already declared in <cstdlib>. If you include the header then you can use the functions, there's no need to try reusing standard names as user defined class names. |
| All times are GMT -4. The time now is 2:03 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC