sinners, repent!
I discovered that in 1997 (then as a fresh senior consultant with
Accenture) I wrote, for personal use, a header with Lakos style include
guards and even "using namespace std;" in the header!
And I wrote e.g. "string const &s" instead of more proper C++ mindset
"string const& s" -- ouch! And just blasted on with blank lines. It
seems that I was very very much in love with blank lines then. And
perhaps also my own name. Writing it TWICE in the header.
Well I can understand the Lakos-style guards; technology had not yet
progressed to the point where they have no advantage. But the "using
namespace std;"??? Did this have something to do with Visual C++ 5.0?
I shudder to think that at this point I had taught C++ at college level.
But on the other hand, this was all before C++ was standardized. Oh
right, that may have something to do with the namespace abuse.
Well I knew my Windows API, evidently, but not quite my C++!
On a positive note, I did already at this time use "Dependencies" and
"Interface" comment lines in C++.
That distinction does make for a very clean structure, when one has
background & experience from some modular language such as (in my case)
Modula-2 and UCSD Pascal. May C++ gain a module concept soon! Real soon!
<code>
////////////////////////////////////////////////////////////////////////////
//
// Module: APP EXCEPTIONS
// interface
//
// First of all, implements std operator new semantics (bad_alloc, nothrow)
// for Visual C++ 5.0 simply by installing a throwing new-handler -- the
// rest is already in place (but undocumented) in the VC++ 5.0 runtime lib.
//
// Secondly, defines an exception class [api_error] as
//
//
// exception
// runtime_error
// api_error
//
//
// Copyright (c) 1997 Alf P. Steinbach
// Author: Alf P. Steinbach
//
#ifdef __APP_EXCEPTIONS_H__
#error [app_exceptions.h] included twice. Guard your #include's!
#else
#define __APP_EXCEPTIONS_H__
#endif
//---------------------------------------- Dependencies:
#ifndef _STDEXCEPT_
#include <stdexcept> // runtime_error
using namespace std;
#endif
#ifndef _NEW_
#include <new> // bad_alloc
using namespace std;
#endif
#ifndef _INC_WINDOWS
#include <windows.h> // GetLastError
#endif
//---------------------------------------- Interface:
// The first constructor uses APIErrorMessage() as the string for what().
// The second constructor lets you specify the string for what().
// The APIErrorMessage() function retrieves the Windows error message text.
class api_error: public runtime_error
{
typedef runtime_error super;
// Construction & destruction:
public:
api_error( DWORD an_api_errorcode = GetLastError() ) throw();
api_error( string const &s, DWORD an_api_errorcode = GetLastError() )
throw();
api_error( api_error const &rhs ) throw();
api_error& operator=( api_error const &rhs ) throw();
virtual ~api_error() throw();
// Accessors:
public:
virtual string const APIErrorMessage() const throw();
virtual DWORD APIErrorCode() const throw();
// State:
protected:
DWORD error_code;
}; // api_error
</code>
Cheers, & may you not, in 2012, commit the sins I did above in 1997,
- Alf