| | |
Declaring a list in a header file
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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
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
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.
C++ Syntax (Toggle Plain Text)
#include<list> class MergeSort{ public: MergeSort(); bool sortedIsEmpty(); int sortedGetLenght(); bool sortedInsert(int); bool sortedRemove(int); int sortedRetrieve(int); int locatePosition(bool); private: List<int> intergerList1; };
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
C++ Syntax (Toggle Plain Text)
#include<iostream> #include <list> using namespace std; #include "MergeSort.h" list<int> integerList1; list<int> integerList2; list<int> integerList3; int main(){ } MergeSort::MergeSort(){ //Empty constructor } bool MergeSort::sortedIsEmpty(){ if(integerList3.empty()){ return true; }else{ return false; } } int MergeSort::sortedGetLenght(){ return integerList3.size(); } bool MergeSort::sortedInsert(list<int> first){ }
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.
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. C++ Syntax (Toggle Plain Text)
#include<list> class MergeSort{ public: MergeSort(); bool sortedIsEmpty(); int sortedGetLenght(); bool sortedInsert(int); bool sortedRemove(int); int sortedRetrieve(int); int locatePosition(bool); private: std::list<int> intergerList1; };
The truth does not change according to our ability to stomach it.
![]() |
Similar Threads
- graphices header file (C)
- Header File (C++)
- header file/ classes (C++)
- Adding to linked list from external file (C)
- compile header file (C++)
- Link source code and header file together? (C++)
- How to write a header file (C++)
Other Threads in the C++ Forum
- Previous Thread: Pls Help
- Next Thread: passing arrays / updating object arrays
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





