February 11, 2000

Where Are Exception Objects Stored?

Consider the following program: class Exception {}; int main() { try { throw Exception(); // where is the exception stored? } catch( Exception & ex) // catch by reference {} } The handler catches the exception by reference, not by value. Catching exception by reference is recommended because it’s more

Heap or Free-Store?

The terms heap and free-store are used interchangeably when referring to dynamically allocated objects. Are there any differences between the two? Technically, free-store is an abstract term referring to unused memory that is available for dynamic allocations. Heap is the data model used by virtually all C++ compilers to implement

Validating Data Entries

Suppose you have an application that reads input from the keyboard. How can you detect whether alphabetic data is being entered into an integer field from a cin statement? The easiest way to validate the user’s input is by having cin read a string rather than a numeric data type

No Member-Function to Pointer-to-Member-Function Conversion

Does you compiler accept the following code? class A { public: void f(int); }; void (A::*pm)(int) = A::f; // #1 no ampersand before A::f A standard-compliant compiler should flag line #1 as an error. Let’s examine it in further detail to see why. The expression A::f is called a qualified-id.

Change Pages Using the Enter Key

Question: How do I display the next page after a user enters data into a field and presses the Enter key? Answer: This is both possible and fairly easy. Here’s the simplest way: Now, when you type anything into that field and then leave the field (by means of the

Generate a Unique Whole Number

Question: How can I generate a unique number using JavaScript? Answer: You can generate random numbers in JavaScript using the Math.random() method. This function returns a fractional random number between 0 and 1. Unlike other languages, JavaScript will initialize a random seed for you automatically so you don’t have to

GetYear() Function Is Not Y2K Compliant

Question: I call the following function to display the date in “month, date, year” format. It displays in the right format (for example, January 7, 2000) in Netscape 4.0. But in Netscape 4.5+, it gives 100. So I try to add 1900, but then it gives 3900. Is this a

Add Keyboard Shortcuts to Your Web Page

With HTML 4.0, you can add keyboard shortcuts to your Web page. To achieve this, you place the ACCESSKEY attribute inside the form element tag. It is advisable to add text information about the shortcut so that the user is aware of the shortcut key to use. In this example,