Declaring a list in a header file

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

Join Date: Sep 2006
Posts: 21
Reputation: JaksLax is an unknown quantity at this point 
Solved Threads: 0
JaksLax's Avatar
JaksLax JaksLax is offline Offline
Newbie Poster

Declaring a list in a header file

 
0
  #1
Sep 6th, 2007
So what I am trying to do is to have a header file which declares lists in it. Everytime I complie it, it does not know what a list is. Here is my header file called MergeSort.h

  1. #include<list>
  2.  
  3.  
  4. class MergeSort{
  5.  
  6. public:
  7.  
  8. MergeSort();
  9. bool sortedIsEmpty();
  10. int sortedGetLenght();
  11. bool sortedInsert(int);
  12. bool sortedRemove(int);
  13. int sortedRetrieve(int);
  14. int locatePosition(bool);
  15.  
  16. private:
  17.  
  18. List<int> intergerList1;
  19.  
  20. };
Here is what the compiler spits at me:

MergeSort.h:18: error: ISO C++ forbids declaration of ‘List’ with no type
MergeSort.h:18: error: expected ‘;’ before ‘<’ token

Basically what I want to do is use this header file for this code called MergeSort.cpp

  1. #include<iostream>
  2. #include <list>
  3. using namespace std;
  4.  
  5. #include "MergeSort.h"
  6.  
  7. list<int> integerList1;
  8. list<int> integerList2;
  9. list<int> integerList3;
  10.  
  11. int main(){
  12.  
  13.  
  14.  
  15.  
  16. }
  17.  
  18. MergeSort::MergeSort(){
  19.  
  20. //Empty constructor
  21.  
  22. }
  23.  
  24. bool MergeSort::sortedIsEmpty(){
  25.  
  26. if(integerList3.empty()){
  27.  
  28. return true;
  29.  
  30. }else{
  31.  
  32. return false;
  33.  
  34. }
  35.  
  36. }
  37.  
  38. int MergeSort::sortedGetLenght(){
  39.  
  40. return integerList3.size();
  41.  
  42. }
  43.  
  44. bool MergeSort::sortedInsert(list<int> first){
  45.  
  46.  
  47.  
  48. }

Now I dont have everything from teh .ccp file in the .h file yet. I am trying to get the .h file to complie first. Can anyone help me by letting me know how to declare a list in a headfer file? Thanks in advance.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 322
Reputation: Hamrick will become famous soon enough Hamrick will become famous soon enough 
Solved Threads: 33
Hamrick's Avatar
Hamrick Hamrick is offline Offline
Posting Whiz

Re: Declaring a list in a header file

 
0
  #2
Sep 6th, 2007
C++ is case sensitive. Change it to list instead of List and if you don't do using namespace std; you have to prefix the name with std.
  1. #include<list>
  2.  
  3.  
  4. class MergeSort{
  5.  
  6. public:
  7.  
  8. MergeSort();
  9. bool sortedIsEmpty();
  10. int sortedGetLenght();
  11. bool sortedInsert(int);
  12. bool sortedRemove(int);
  13. int sortedRetrieve(int);
  14. int locatePosition(bool);
  15.  
  16. private:
  17.  
  18. std::list<int> intergerList1;
  19.  
  20. };
The truth does not change according to our ability to stomach it.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 21
Reputation: JaksLax is an unknown quantity at this point 
Solved Threads: 0
JaksLax's Avatar
JaksLax JaksLax is offline Offline
Newbie Poster

Re: Declaring a list in a header file

 
0
  #3
Sep 6th, 2007
Thanks that worked like a charm
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC