🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by thawk1@ibmpcug.U Tue, 07 Mar 1989 15:38
Some Questions from a C++ beginner
#2718
Author: thawk1@ibmpcug.U
Date: Tue, 07 Mar 1989 15:38
97 lines
2835 bytes
I have two questions that are bothering me at the moment and I wondered
if some kind person in netland could enlighten me..

The first concerns tempoary class instances ; consider the following

	'database' is a class that has a constructor that takes a
	database name and opens it. It also read the structure of
	the record into the data area of the class instance. Its
	destructor closes the file and cleans up memory... It has
	a member function called create that copys a record structure
	from a database reference passed to it and creates a new
	(un-nammed) database of the same structure..

	I wish to do the following:

	database xx;             // un-named database with no structure

	void	copy_dbf( char *name )
	{

		xx.create( database( "TEST" ) );

		.......... other statements ..........

	}

	My first question is; is the scope of " database( "TEST" ) " ( a
	tempoary class created soley to obtain the structure of another
	database) the scope of the whole function "copy_dbf" or is its scope
	limited to the stage of constructing the stack frame for the
	" xx.create( ... ); " call.. In the case of a class that uses files
	it is important that I know were the clean-up is done prior to executin
	further code in that function... If this is valid in the language.
	what is the status in the various implementations?. ( I am using
	Zortech C++ 1.05 and Glockenspiel Designer C++ Beta 2A , both on
	Msdos 3.2 ).. This question is simular in vein to the "for" loop
	counter variable question, that has been recently discussed..

Second Question...

	I am trying to implement a generic error handler class

	ie:

	class error_handler
	{
		jmpbuf	error_point;
		int	error_defined;
	public:

	inline  error_handler( void )
	{
		error_defined = 0;
	}

	inline  virtual int error( void )
	{
		return( setjmp( error_point));
	}

	inline  virtual void error( int error_code )
	{
		longjmp( error_point, error_code );
	}
	}

	The theory is that the handle could be inherited into complex
	classes and allows the following.......

	{
		database xx;
		database yy;

		if( xx.error() || yy.error())
		{
			printf("Database Error\n");
			exit(0);
		}

	The member functions of the class could call error(n) to handle
	fatal errors.....

	Can anybody think of any good reason for not using this scheme or
	has anybody got any experience with a mainstream C++ compiler that
	cannot handle this construction... I would appreaciate it as I am
	hoping to write some libarys that will be ported to various C++
	systems and I wish to minimise the compiler dependancys.....

Thank you for all you forthcomming help
	Tim hawkins  thawk1@ibmpcug
	Tel 44 242 581145 .................

--
Automatic Disclaimer:
The views expressed above are those of the author alone and may not
represent the views of the IBM PC User Group.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads