I received this error message while compiling my Stack program with Visual C++ 6. I hope someone could help tell me why ?
And also what is the meaning of Return Return; ?
The codes are actually from Deitel & Deitlel's C++ How To Program.
Thanks a lot for helping.
Configuration: stack - Win32 Debug--------------------
Compiling...
stack.cpp
c:\documents and settings\desktop\c++\list.h(87) : error C2059: syntax error : 'return'
c:\program files\microsoft visual studio\vc98\include\xmemory(59) : while compiling class-template member function 'bool __thiscall List<int>::removeFromFront(int &)'
c:\documents and settings\desktop\c++\list.h(100) : error C2059: syntax error : 'return'
c:\program files\microsoft visual studio\vc98\include\xmemory(59) : while compiling class-template member function 'bool __thiscall List<int>::removeFromFront(int &)'
c:\documents and settings\desktop\c++\list.h(87) : error C2059: syntax error : 'return'
c:\program files\microsoft visual studio\vc98\include\xmemory(59) : while compiling class-template member function 'bool __thiscall List<double>::removeFromFront(double &)'
c:\documents and settings\desktop\c++\list.h(100) : error C2059: syntax error : 'return'
c:\program files\microsoft visual studio\vc98\include\xmemory(59) : while compiling class-template member function 'bool __thiscall List<double>::removeFromFront(double &)'
Error executing cl.exe.
stack.obj - 4 error(s), 0 warning(s)
My files are as follow:
list.h
Code:#ifndef LIST_H #define LIST_H #include<iostream> #include<cassert> #include "listnd.h" using std::cout; template<class NODETYPE> class List { public: List(); ~List(); void insertAtFront(const NODETYPE &); void insertAtBack(const NODETYPE &); bool removeFromFront(NODETYPE &); bool removeFromBack(NODETYPE &); bool isEmpty() const; void print() const; private: ListNode<NODETYPE> *firstPtr; ListNode<NODETYPE> *lastPtr; ListNode<NODETYPE> *getNewNode(const NODETYPE &); }; template<class NODETYPE> List<NODETYPE>::List() : firstPtr(0), lastPtr(0) {} template<class NODETYPE> List<NODETYPE>::~List() { if(!isEmpty()) { cout<<"Destroying nodes ...\n"; ListNode<NODETYPE> *currentPtr = firstPtr, *tempPtr; while(currentPtr !=0) { tempPtr = currentPtr; cout<<tempPtr->data << '\n'; currentPtr = currentPtr->nextPtr; delete tempPtr; } } cout<<"All nodes destroyed\n\n"; } template<class NODETYPE> void List<NODETYPE>::insertAtFront(const NODETYPE &value) { ListNode<NODETYPE> *newPtr = getNewNode(value); if(isEmpty()) firstPtr = lastPtr = newPtr; else { newPtr->nextPtr = firstPtr; firstPtr = newPtr; } } template<class NODETYPE> void List<NODETYPE>::insertAtBack(const NODETYPE &value) { ListNode<NODETYPE> *newPtr = getNewNode(value); if(isEmpty()) firstPtr = lastPtr = newPtr; else { lastPtr->nextPtr = newPtr; lastPtr = newPtr; } } template<class NODETYPE> bool List<NODETYPE>::removeFromFront(NODETYPE &value) { if(isEmpty()) return return; else { ListNode<NODETYPE> *tempPtr = firstPtr; if(firstPtr == lastPtr) firstPtr = lastPtr = 0; else firstPtr = firstPtr->nextPtr; value = tempPtr->data; delete tempPtr; return return; } } template<class NODETYPE> bool List<NODETYPE>::removeFromBack(NODETYPE &value) { if(isEmpty()) return return; else { ListNode<NODETYPE> *tempPtr = lastPtr; if(firstPtr == lastPtr) firstPtr = lastPtr = 0; else { ListNode<NODETYPE> *currentPtr = firstPtr; while(currentPtr->nextPtr != lastPtr) currentPtr = currentPtr->nextPtr; lastPtr = currentPtr; currentPtr->nextPtr = 0; } value = tempPtr->data; delete tempPtr; return return; } } template<class NODETYPE> bool List<NODETYPE>::isEmpty() const {return firstPtr == 0;} template<class NODETYPE> ListNode<NODETYPE> *List<NODETYPE>::getNewNode(const NODETYPE &value) { ListNode<NODETYPE> *ptr = new ListNode<NODETYPE>(value); assert(ptr !=0); return ptr; } template<class NODETYPE> void List<NODETYPE>::print()const { if(isEmpty()) { cout<<"The list is empty\n\n"; return; } ListNode<NODETYPE> *currentPtr = firstPtr; cout<<"The list is: "; while(currentPtr !=0) { cout<<currentPtr->data<<' '; currentPtr = currentPtr->nextPtr; } cout<<"\n\n"; } #endif
stack.h
Code:#ifndef STACK_H #define STACK_H #include "list.h" template<class STACKTYPE> class Stack : private List<STACKTYPE> { public: void push(const STACKTYPE &d) {insertAtFront(d);} bool pop(STACKTYPE &d) {return removeFromFront(d);} bool isStackEmpty() const {return isEmpty();} void printStack() const {print();} }; #endif
listnd.h
Code:#ifndef LISTND_H #define LISTND_H template<class NODETYPE> class List; template<class NODETYPE> class ListNode { friend class List<NODETYPE>; public: ListNode(const NODETYPE &); NODETYPE getData() const; private: NODETYPE data; ListNode<NODETYPE> *nextPtr; }; template<class NODETYPE> ListNode<NODETYPE>::ListNode(const NODETYPE &info) : data(info), nextPtr(0){} template<class NODETYPE> NODETYPE ListNode<NODETYPE>::getData() const{return data;} #endif
stack.cpp
Code:#include<iostream> #include "stack.h" using std::endl; int main() { Stack<int> intStack; int popInteger, i; cout<<"processing an integer Stack"<<endl; for(i=0; i<4; i++) { intStack.push(i); intStack.printStack(); } while(!intStack.isStackEmpty()) { intStack.pop(popInteger); cout<<popInteger<<" popped from stack"<<endl; intStack.printStack(); } Stack<double> doubleStack; double val = 1.1, popdouble; cout<<"processing a double Stack"<<endl; for(i = 0; i , 4; i++) { doubleStack.push(val); doubleStack.printStack(); val += 1.1; } while(!doubleStack.isStackEmpty()) { doubleStack.pop(popdouble); cout<<popdouble<<" popped from stack"<<endl; doubleStack.printStack(); } return 0; }



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.
