June 11, 1998

DevX - Software Development Resource

auto_ptr<>: your safe guard against memory leaks

The Standard Library supplies the class template auto_ptr which automatically deallocates heap memory. Likewise, local objects are reclaimed in case of exiting their scope or during “stack unwinding” caused by

DevX - Software Development Resource

extern “C” linkage declaration

It is not uncommon for C++ code fragments to be called by non-C++ programs such as a C-based communication software, COBOL based TP monitors and the likes. However, global functions

DevX - Software Development Resource

Exception-free version of operator new

Operator new throws an exception of type std::bad_alloc when it fails to allocate the requested amount of memory. Yet in some circumstances, or due to performance considerations, throwing an exception

DevX - Software Development Resource

That’s what friends are for

A class can declare external functions or other classes as friends. Friendship grants full access to all of the grantor’s members, even private and protected ones: void encrypt (string &