July 30, 1999

A Reference to a Reference is Illegal

What is wrong with this code snippet? #include #include using std::string;using std::list;class Node {/*..*/};int main(){ list ln; //error} If you try to compile this example, your compiler will issue numerous compilation errors. The problem is that list has member functions that take or return T&. In other words, the compiler

Another Technique of Marking Line Continuation

When a long line of a quoted string has to be broken, you can use the line continuation marker as described in the tip Use the Continuation Marker Before a Line Break. However, both C and C++ offer another method of breaking long lines, which relies on the fact that

Random Integers Over an Integer Interval

The java.util.Random class has a public int nextInt() method that returns a randomly selected integer, but there is no innate method in that class to create a random number over an integer interval, say [x,y]. However, you can use the public double nextDouble() method of the Random class to obtain

Throwing Exceptions to Report an Error During Object’s Construction

Many implementations still do not support exception handling very well. Therefore, you can implement, using global variables and passing a parameter to the constructor, instead. However, on implementations that support exception handling, throwing an exception is the preferred method of reporting runtime errors during an object’s construction. The advantages of

Reporting an Error During Object’s Construction

Constructors have no return value (not even void). Therefore, you have to use alternative techniques of reporting errors during object’s construction. There are three common techniques of reporting such errors. The first technique uses C-style error handling: when an error occurs during construction, the constructor assigns an error value to

Find Text Between Two Strings

This function is useful for returning a portion of a string between two points in the string. You could, for example, extract a range name returned by Excel found between parentheses: Function Between(sText As String, sStart As _ String, sEnd As String) As String Dim lLeft As Long, lRight As

Adding Multiple Delimited Entries to a List Box

The typical way of entering user-specified data into a list box is one entry at a time; however, you can accept multiple delimited entries at once and add them to a list box with a call to this function. Passing the function a delimited string fills the list box with

Repeat Performance

A simple loop through your main string lets you count the occurrences of a specified character or string. This function is useful for determining if enough commas appear in your comma-delimited string: Function Tally(sText As String, sFind As String) As Long Dim lFind As Long Dim lLast As Long Do

Using Parameters to Report an Error During Object’s Construction

Using global flags to indicate runtime errors has many disadvantages: Global variables are problematic in multithreaded environments. In addition, programmers might forget to test the value of the global error flag and consequently, the error is not properly handled. Another method of reporting runtime errors during the construction of an

No more posts to show