Thread: Return Return Error

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    32

    Angry Return Return Error

    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;
    }
    Last edited by javacvb; 12-16-2003 at 11:00 AM.
    [SIZE= 4]My favorite search engine is http://www.ultimasurf.com [/size]

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Those should be either return false; or return true; or something along those lines. I don't know why that would be there in the book.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    return is a C++ keyword, as such, the construct
    Code:
    return return;
    is both nonsensical, and illegal. Try returning true and false as required, that should work a little bit better for you.
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    32
    Is Deitel & Deitel teaching a wrong doctrine here?

    I am concerned because I have 8 programming books by them. And these authors are making tons of money.



    The comments given by them were "delete successful" or 'delete unsuccessful".
    [SIZE= 4]My favorite search engine is http://www.ultimasurf.com [/size]

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Is Deitel & Deitel teaching a wrong doctrine here?
    In this case, it's either a printing error or something equally exceptional. Since such a construct will never compile, any book that seriously teaches it would be completely wrong. However, from what I've seen the Deitel books aren't exactly the pinnacle of good programming form.

    >And these authors are making tons of money.
    Yes, they are. All of my best books on programming cost less than any one of the Deitel books and they're worth far more.
    My best code is written with the delete key.

  6. #6
    Registered User
    Join Date
    May 2003
    Posts
    32
    I tried true & false as suggested & the program works but they are in infinite loop. I haven't figure which one need to be return as false & which one should be true.




    Should I write to Deitel & Deitel to complain?
    [SIZE= 4]My favorite search engine is http://www.ultimasurf.com [/size]

  7. #7
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    I have C++ How to Program 4th Ed. and it does not have that typo. Here are the correct codes.
    Code:
    template<class NODETYPE>
    bool List<NODETYPE>::removeFromFront(NODETYPE &value)
    {
    	if(isEmpty())
    		return false;
    
    	else
    	{
    		ListNode<NODETYPE> *tempPtr = firstPtr;
    
    		if(firstPtr == lastPtr)
    			firstPtr  = lastPtr = 0;
    		else
    			firstPtr = firstPtr->nextPtr;
    
    		value = tempPtr->data;
    		delete tempPtr;
    		return true;
    	}
    }
    
    template<class NODETYPE>
    bool List<NODETYPE>::removeFromBack(NODETYPE &value)
    {
    	if(isEmpty())
    	return false;
    	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 true;
    	}
    }
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    > cout<<"processing a double Stack"<<endl;

    > for(i = 0; i , 4; i++)

    Should be:
    for(i = 0; i < 4; i++)

  9. #9
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    Originally posted by swoopy
    > cout<<"processing a double Stack"<<endl;

    > for(i = 0; i , 4; i++)

    Should be:
    for(i = 0; i < 4; i++)
    No this typo, either, in my Deitel's book
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  2. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  3. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  4. using c++ in c code
    By hannibar in forum C Programming
    Replies: 17
    Last Post: 10-28-2005, 09:09 PM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM