| | |
Linked List
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2004
Posts: 15
Reputation:
Solved Threads: 0
Hello all, I have almost completed a program that will take 8 numbers from a user and store it in a linked list. Once that is done It will ask for another entry and determine the location of this new entry and how many items are currently bigger than the new entry. I have (pretty much") 95% of it written out but am having problems with my header file (below). I just have to modify my main.cpp file to complete the program but am having problems in the header where I'm getting errors in the codeLL function. I cannot figure out why it keeps giving off this error. I thought I had written everything correctly. Please let me know if you have any suggestions or if you see something that Im just not seeing
Thanks in advance
--------------------Configuration: Linked List Main - Win32 Debug--------------------
Compiling...
Linked List Main.cpp
c:\documents and settings\steve\desktop\project 4 linked list\linkedlist.h(29) : warning C4183: 'deleteLL': member function definition looks like a ctor, but name does not match enclosing class
c:\documents and settings\steve\desktop\project 4 linked list\linkedlist.h(139) : see reference to class template instantiation 'LinkedList<DataType>' being compiled
c:\documents and settings\steve\desktop\project 4 linked list\linkedlist.h(32) : error C2063: 'copyLL' : not a function
c:\documents and settings\steve\desktop\project 4 linked list\linkedlist.h(139) : see reference to class template instantiation 'LinkedList<DataType>' being compiled
c:\documents and settings\steve\desktop\project 4 linked list\linkedlist.h(32) : error C2040: 'copyLL' : 'class LinkedList<DataType>::Node *(class LinkedList<DataType>::Node *)' differs in levels of indirection from 'int'
c:\documents and settings\steve\desktop\project 4 linked list\linkedlist.h(139) : see reference to class template instantiation 'LinkedList<DataType>' being compiled
c:\documents and settings\steve\desktop\project 4 linked list\linkedlist.h(32) : fatal error C1903: unable to recover from previous error(s); stopping compilation
c:\documents and settings\steve\desktop\project 4 linked list\linkedlist.h(139) : see reference to class template instantiation 'LinkedList<DataType>' being compiled
Error executing cl.exe.
Linked List Main.obj - 3 error(s), 1 warning(s)
--------------------------------------------------------------------------------
Hi I've included a basic main which I am using to test the header file
Thanks in advance
--------------------Configuration: Linked List Main - Win32 Debug--------------------
Compiling...
Linked List Main.cpp
c:\documents and settings\steve\desktop\project 4 linked list\linkedlist.h(29) : warning C4183: 'deleteLL': member function definition looks like a ctor, but name does not match enclosing class
c:\documents and settings\steve\desktop\project 4 linked list\linkedlist.h(139) : see reference to class template instantiation 'LinkedList<DataType>' being compiled
c:\documents and settings\steve\desktop\project 4 linked list\linkedlist.h(32) : error C2063: 'copyLL' : not a function
c:\documents and settings\steve\desktop\project 4 linked list\linkedlist.h(139) : see reference to class template instantiation 'LinkedList<DataType>' being compiled
c:\documents and settings\steve\desktop\project 4 linked list\linkedlist.h(32) : error C2040: 'copyLL' : 'class LinkedList<DataType>::Node *(class LinkedList<DataType>::Node *)' differs in levels of indirection from 'int'
c:\documents and settings\steve\desktop\project 4 linked list\linkedlist.h(139) : see reference to class template instantiation 'LinkedList<DataType>' being compiled
c:\documents and settings\steve\desktop\project 4 linked list\linkedlist.h(32) : fatal error C1903: unable to recover from previous error(s); stopping compilation
c:\documents and settings\steve\desktop\project 4 linked list\linkedlist.h(139) : see reference to class template instantiation 'LinkedList<DataType>' being compiled
Error executing cl.exe.
Linked List Main.obj - 3 error(s), 1 warning(s)
C++ Syntax (Toggle Plain Text)
#ifndef LINKEDLIST #define LINKEDLIST #include<iostream.h> template<typename DataType> class LinkedList { private: class Node { public: // Makes it accessible (public) by class Node DataType data; Node *next; }; Node *first; int mySize; LinkedList::deleteLL() { Node *tempP=first, *disposeP; while (tempP!=0) { disposeP=tempP; tempP=tempP->next; delete disposeP; } return; } Node* LinkedList::copyLL(Node* source) { if (source==0) return 0; Node* newH=new Node; Node *tempP=newH; newH->data=source->data; source=source->next; while (source!=0) { tempP->next=newNode; tempP->data=source->data tempP=tempP->next; source=source->next; } temp->next=0; return newH; } public: LinkedList::LinkedList() { mySize=0; first=0; } LinkedList::~LinkedList() { deleteLL(); } LinkedList::LinkedList( const LinkedList &source) { mySize=source.first; first=copyLL(source.first); } LinkedList& LinkedList::operator=(const LinkedList& s) { if (this!=&s) { deleteLL(); mySize=s.mySize; first=copyLL(s.first) } return *this; } bool LinkedList::empty() { return (first==0); } void LinkedList::insert(DataType item, unsigned pos) { if (pos>mySize+1) { cout<<"Illegal position to insert:"<<pos<<endl; return; } mySize++ Node* newNode=newNode; newNode->data=item; Node* prev=first; for (int i=1, i<pos, i++) prev=prev->next; newNode->next=prev->next; prev->next=newNode; } void LinkedList::delete (dataType item) { mySize--; Node* tempP=first; Node* prev=0; while (tempP!=0 && tempP->data!=item) { prev=tempP; tempP=tempP->next; } if (tempP!=0 && tempP->data==item) { prev->next=tempP->next; delete tempP; } else cout<<"Item to delete not found"<<endl; return; } int LinkedList::locate(DataType item) { int position=0; Node* ptr=first; while(ptr->data<item &&ptr!=0) { position++; ptr=ptr->next; } return position } void LinkedList::traverse() { Node *temp=first; while (tempP!=0) { Process(tempP->data); tempP=tempP->next; } return; } }; #endif
--------------------------------------------------------------------------------
Hi I've included a basic main which I am using to test the header file
C++ Syntax (Toggle Plain Text)
#include "LinkedList.h" #include<string> using namespace std; main() { }
•
•
Join Date: Jul 2004
Posts: 15
Reputation:
Solved Threads: 0
Hi, I gave deleteLL a return type and tried removing LinkedList from 2 functions but that still did not work. I am still getting the same 3 errors. Im just confused as to why its telling me that copyLL is not a function when deleteLL is almost the same and seems to be working.
•
•
•
•
Originally Posted by Chainsaw
LinkedList::deleteLL() has no return value. That's why the compiler thinks it looks like constructor.
Also, minor point, the LinkedList:: is not nescessary since you are enclosed in that class.
You changed it to something like "void deleteLL()" and you still get the complaint that "'deleteLL': member function definition looks like a ctor, but name does not match enclosing class"?
That's weird; maybe because its a template I'm not reading it right.
Another thing to think about is to pass a const ref to DataType when you pass it in for searching or copying. That way if it is of any significant size you won't be making extra work (making temp copies and using the copy constructor) for the compiler.
That's weird; maybe because its a template I'm not reading it right.
Another thing to think about is to pass a const ref to DataType when you pass it in for searching or copying. That way if it is of any significant size you won't be making extra work (making temp copies and using the copy constructor) for the compiler.
![]() |
Similar Threads
- how to create linked list? (C)
- Removing an item from head of linked list (C)
- Cannot figure out how to implement linked list and rbtree for a project! (Java)
- help by sorting a simply linked list (C)
Other Threads in the C++ Forum
- Previous Thread: C++ Builder 6
- Next Thread: File processing problem
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop 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 integer java linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets





