anyone plz help me wif dis error?TQ

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2008
Posts: 4
Reputation: ventrica is an unknown quantity at this point 
Solved Threads: 0
ventrica ventrica is offline Offline
Newbie Poster

anyone plz help me wif dis error?TQ

 
0
  #1
Feb 16th, 2008
i hav write a coding regarding to lists topic. and i had found about 3 error which i cant solve. any1 here who can help me wif dis error? i m very appreciate 4 all of ur help..TQ..dis is my coding and the error..TQ


  1. List.h
  2.  
  3. #ifndef LIST_H
  4. #define LIST_H
  5.  
  6. template < class DataType>
  7. class List
  8. {
  9. private:
  10. class Node
  11. {
  12. public:
  13. DataType data;
  14. Node * link;
  15. };
  16.  
  17. Node *pHead;
  18. Node *pCurr;
  19. int numItem;
  20.  
  21. public:
  22. List();
  23. ~List();
  24. void AddToFront();
  25. void Traverse(DataType, int &);
  26. void printData();
  27. int NumberOfItem();
  28. };
  29. #endif



List.cpp
  1. #include <iostream>
  2. using namespace std;
  3. #include "List.h"
  4.  
  5. template<class DataType>
  6. List<DataType>::List()
  7. {
  8. numItem = 0;
  9. pHead = 0;
  10. }
  11.  
  12. template <class DataType>
  13. List<DataType>::~List() {}
  14.  
  15. template <class DataType>
  16. void List<DataType>::AddToFront()
  17. {
  18. DataType item;
  19. Node *pNew = new Node;
  20. cout << "Enter data : ";
  21. cin >> item;
  22. pNew->data = item;
  23. pNew->link = pHead;
  24. pHead = pNew;
  25. numItem++;
  26. }
  27.  
  28. template <class DataType>
  29. void List <DataType>::printData()
  30. {
  31. pCurr = pHead;
  32. while (pCurr != 0)
  33. {
  34. cout << pCurr->data << " ";
  35. pCurr = pCurr->link;
  36. }
  37. cout << "\n";
  38. }
  39.  
  40. template <class DataType>
  41. int List<DataType>::NumberOfItem()
  42. {
  43. return numItem;
  44. }
  45.  
  46. template <class DataType>
  47. bool List<DataType>::Traverse (DataType target, int &loc)
  48. {
  49. if (numItem == 0)
  50. cout <<"There is no item in the list" <<endl;
  51. else
  52. {
  53. pCurr = pHead;
  54. loc = 0;
  55. while (pCurr -> data != target && pCurr -> link != 0)
  56. {
  57. pCurr = pCurr -> link;
  58. loc++;
  59. }
  60. if (pCurr -> data == target)
  61. return true;
  62. else
  63. return false;
  64. }
  65.  
  66. }


ListMain.cpp
  1. #include <iostream>
  2. #include<string>
  3. using namespace std;
  4. #include "List.h"
  5.  
  6. void main()
  7. {
  8. int target;
  9. int location;
  10.  
  11. List<int> list;
  12. for (int i = 1; i <4; i++)
  13. {
  14. list.AddToFront();
  15. }
  16.  
  17. cout << "\nNumber of Item Now: " <<list.NumberOfItem();
  18. cout << "\nThe list are : " <<endl;
  19. list.printData();
  20.  
  21. cout<<"\nEnter the search item : ";
  22. cin>> target;
  23.  
  24. if (list.Traverse(target, location) == true)
  25. {
  26. cout<< "Item is found at location : "
  27. <<location<<endl;
  28. }
  29. else
  30. {
  31. cout << "Item is not found \n";
  32. }
  33. }


ERROR:

c:\Documents and Settings\VeNTRiCaLiM\Desktop\assignment5\6example1\ListMain.cpp(24): warning C4805: '==' : unsafe mix of type 'void' and type 'bool' in operation


c:\Documents and Settings\VeNTRiCaLiM\Desktop\assignment5\6example1\ListMain.cpp(24): error C2120: 'void' illegal with all types


c:\Documents and Settings\VeNTRiCaLiM\Desktop\assignment5\6example1\List.cpp(66): error C2244: 'List<DataType>::Traverse' : unable to match function definition to an existing declaration



can tel me where should i change in order to solve the error?TQ
Last edited by Ancient Dragon; Feb 17th, 2008 at 11:58 pm. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: anyone plz help me wif dis error?TQ

 
1
  #2
Feb 17th, 2008
Don't use void main().
Always use int main().

In "List.h" the Traverse() method is (incorrectly) prototyped as void Traverse( DataType, int& ). In "List.cpp" it is (correctly) defined as bool Traverse( DataType, int& ).

Please don't use leetspeak or other weenie talk. (Be kind to those for whom English is not their first language.)

Hope this helps.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,461
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 254
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: anyone plz help me wif dis error?TQ

 
0
  #3
Feb 17th, 2008
A different translator's versions of the error messages:
list.cpp
*** {BD Software Proxy c++ v3.43a for gcc} STL Message Decryption is ON! ***
list.cpp:50: error: prototype for
`bool List<DataType>::Traverse(DataType, int &)' does not match any in
class `List<DataType>'
List.h:23: error: candidate is: void List<DataType>::Traverse(DataType, int &)
list.cpp:50: error: template definition of non-template
`bool List<DataType>::Traverse(DataType, int &)'
main.cpp
*** {BD Software Proxy c++ v3.43a for gcc} STL Message Decryption is ON! ***
main.cpp:7: error: `main' must return `int'
main.cpp: In function `int main(...)':
main.cpp:24: error: void value not ignored as it ought to be
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 4
Reputation: ventrica is an unknown quantity at this point 
Solved Threads: 0
ventrica ventrica is offline Offline
Newbie Poster

Re: anyone plz help me wif dis error?TQ

 
0
  #4
Feb 17th, 2008
Originally Posted by Duoas View Post
Don't use void main().
Always use int main().

In "List.h" the Traverse() method is (incorrectly) prototyped as void Traverse( DataType, int& ). In "List.cpp" it is (correctly) defined as bool Traverse( DataType, int& ).

Please don't use leetspeak or other weenie talk. (Be kind to those for whom English is not their first language.)

Hope this helps.
Thanks for your reply. you means in "List.h", the Traverse() method is incorrectly, so, what should i change in the coding to solve the problem? Somemore, in "List.cpp" , is it have to change the traverse method also?thank you for your kindly reply.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,089
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Solved Threads: 164
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: anyone plz help me wif dis error?TQ

 
0
  #5
Feb 17th, 2008
> ... so, what should i change in the coding to solve the problem?
change the return type from void to bool
template < class DataType>
class List
{
    // ...
    bool Traverse(DataType, int &);
    // ...
};
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 4
Reputation: ventrica is an unknown quantity at this point 
Solved Threads: 0
ventrica ventrica is offline Offline
Newbie Poster

Re: anyone plz help me wif dis error?TQ

 
0
  #6
Feb 17th, 2008
Originally Posted by vijayan121 View Post
> ... so, what should i change in the coding to solve the problem?
change the return type from void to bool
template < class DataType>
class List
{
    // ...
    bool Traverse(DataType, int &);
    // ...
};

i change already and more errors come out. this is the error:

6example1 error LNK2019: unresolved external symbol "public: __thiscall List<int>::~List<int>(void)" (??1?$List@H@@QAE@XZ) referenced in function _main


6example1 error LNK2019: unresolved external symbol "public: bool __thiscall List<int>::Traverse(int,int &)" (?Traverse@?$List@H@@QAE_NHAAH@Z) referenced in function _main


6example1 error LNK2019: unresolved external symbol "public: void __thiscall List<int>::printData(void)" (?printData@?$List@H@@QAEXXZ) referenced in function _main


6example1 error LNK2019: unresolved external symbol "public: int __thiscall List<int>::NumberOfItem(void)" (?NumberOfItem@?$List@H@@QAEHXZ) referenced in function _main


6example1 error LNK2019: unresolved external symbol "public: void __thiscall List<int>::AddToFront(void)" (?AddToFront@?$List@H@@QAEXXZ) referenced in function _main


6example1 error LNK2019: unresolved external symbol "public: __thiscall List<int>::List<int>(void)" (??0?$List@H@@QAE@XZ) referenced in function _main


6example1 fatal error LNK1120: 6 unresolved externals


so..what should i do?Thanks
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: anyone plz help me wif dis error?TQ

 
0
  #7
Feb 18th, 2008
Alas, (I hope you are sitting down), the error is explained here:
C++ FAQ Lite: Why am I getting errors when my template-derived-class uses a nested type it inherits from its template-base-class?

I've never encountered this problem before (I've never tried to do what you are doing) but I'll poke around a bit and see if there is a solution.

Unless, of course, someone else here knows the answer...
Last edited by Duoas; Feb 18th, 2008 at 1:06 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,089
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Solved Threads: 164
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: anyone plz help me wif dis error?TQ

 
0
  #8
Feb 18th, 2008
the functions for which you get a linker error are only declared in List.h. they are defined in List.cpp.

the pedantic answer would be: to use templates without their definition being visible, they must be exported. ie. in List.cpp, they must be defined this way:
  1. #include "List.h"
  2. export template<class DataType>
  3. List<DataType>::List()
  4. {
  5. numItem = 0;
  6. pHead = 0;
  7. }
  8. // etc
however, most current compilers do not support the export keyword. ( Comeau C++ being the notable exception)

a practical solution would be: move the definitions from List.cpp to List.h (and throw the now empty List.cpp away).
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum


Views: 1524 | Replies: 7
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC