November 16, 2005

Safely Downcast Pointers Without dynamic_cast Overhead

Suppose you have a class hierarchy and you plan to do some downcasts. Try writing virtuals in the root class to do the downcasting to NULL for each of the subclasses. Then, write each subclass so it downcasts to itself statically. I run Debian and gcc 3.4.3 on a modern

Constructing Strings of Repeated Characters in T-SQL

Sometimes you need to display a string of characters of a specified length for a column value in a SQL query. To this end, SQL Server supports a function called Replicate() which takes two parameters: the character you want to print and the count (the number of times you want

Write a Standalone Java Application Without a Main Method

Normally, you need a main method in a Java class if you want to run that class from the command line. However, there is a little trick that allows you to run one without a main method: class NoMainMethod{ static { System.out.println(“Look ma! no main method”); System.exit(0); }} The reason

Enable Day-click Selection for an ASP Calendar Control

The following code assigns an OnClick event to each calendar cell by altering the way the calendar control renders the cells containing the days. When clicked, the calendar posts back the day number of the day that was clicked: Sub ca_DayRender(sender As Object, e As DayRenderEventArgs) Dim d as CalendarDay