🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #1357

(none)

#1357
From: Mark Weiss
Date: Thu, 07 Jan 1993 20:11
152 lines
3027 bytes
I'm having a problem with version 2.3.3.
The source coude is below.  When the include statement at
(approximately) line 47 is commented out, the program compiles.
When it's in, a get a parse error on the }; at the end of the class.
The included file has only two blank lines, so that's not the problem!

Thanks,

--Mark Weiss
weiss@fiu.edu

-------------------------------------

#include <iostream.h>

void
error( char *s )
{
	cerr << s << "\n";
}

//SF fig3_41
template <class element_type>
class stack
{
    private:
	// The stack is a linked list with no header.

	struct node
	{
		element_type element;
		struct node *next;

		node( element_type e = 0, struct node *n = 0 )
		{
			element = e;  next = n;
		}
	};

	typedef struct node *node_ptr;

	node_ptr stack_top;


    public:
	// Default stack size is meaningless.
	stack( unsigned int max_size = 100 ) : stack_top ( 0 ) { };
	stack( stack & value );

	//Destructor
	~stack( );

	void push( element_type x );
	void pop( );
	element_type pop_and_top( );
	element_type top( );
	int is_empty( ) { return stack_top == 0; }
//STOP
#include "print_stack.cc"		// THIS IS THE PROBLEM
//START

};
//EF

//template <class element_type>
//stack<element_type>::stack( stack & value )
//{
//}
	
//SF fig3_42
template <class element_type>
inline void stack<element_type>::push( element_type x )
{
	node_ptr p = new node( x, stack_top );

	if( !p )
		error( "Out of memory" );
	else
		stack_top = p;
}
//EF

//SF fig3_44
template <class element_type>
inline void stack<element_type>::pop( )
{
	node_ptr p;

	if( is_empty( ) )
		error( "Empty stack" );
	else
	{
		p = stack_top->next;
		delete stack_top;
		stack_top = p;
	}
}
//EF

//SF fig3_45
template <class element_type>//L1
inline element_type stack<element_type>::pop_and_top( )
{
	element_type top_element = top( );

	if( !is_empty( ) )
		pop( );

	return top_element;
}
//EF

//SF fig3_46
template <class element_type>
stack<element_type>::~stack( )
{
	node_ptr p = stack_top;

	while( p )
	{
		node_ptr after_p = p->next;
		delete p;
		p = after_p;
	}
}
//EF

//SF fig3_43
template <class element_type>
inline element_type stack<element_type>::top( )
{
	if( is_empty( ) )
		error( "Empty stack" );

	return stack_top->element;
}
//EF

main( )
{
	stack<int> S;

	for( int i=1; i<=10; i++ )
		S.push( i );
	cout << "Elements pushed\n";
	//S.rec_print_stack( cout );
	cout << "Result from pushing.\n";
	//S.print_stack( cout );
	cout << "Result from pushing.\n";
	while( !S.is_empty( ) )
		cout << S.pop_and_top( ) << "\n";
}
Technical Details
Message-ID: <9301072011.AA11054@scs.fiu.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!scs.fiu.edu!weiss

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!scs.fiu.edu!weiss
From: weiss@scs.fiu.edu (Mark Weiss)
Subject: (none)
Message-ID: <9301072011.AA11054@scs.fiu.edu>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Thu, 7 Jan 1993 20:11:28 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 155