February 2, 2001

A Beginner’s Checklist

Beginners and even experienced programmers who switch to a new compiler suddenly discover that their programs don’t compile anymore. Sometimes the programs compile but produce numerous warning messages. In most cases, the causes of this are common. Here is a short checklist for troubleshooting such frequent errors and omissions. Avoid

MS Default Pointer Value

Don’t forget that MS compiler initiates pointers with 0xCCCCCCCC value. In this case: void *p; … //do something here… if (p!=NULL) delete p; // Memory violation The right way void* p = NULL;Or if (p!=NULL && p != 0xCCCCCCCC ) delete p;

I/O Formatting With Stringstream

The sprintf() function isn’t type-safe, it doesn’t support user-defined types and it’s a common source of buffer overflow bugs. In C++, there’s a better alternative to sprintf(), namely stringstream objects. The following function template accepts a value of any type and writes it into a user-supplied string s: #include using

Different Uses For Sizeof Operator

Sizeof is a useful operator because it reports both the amount of memory that data items take and the number of bytes that data types. For instance: cout

Check Whether a Given Key Exists in a Collection

It is unfortunate that VB5 does not provide a quick way to check if an item with a certain key exists in a collection. This results in errors if an item with an existing key is added or access is attempted with a key not existing in the collection. Typically,

Take Control of the Threads Created By a Program

Whenever a thread is created in a program, it is unknown when it will execute. This means there may be cases where the parent program has finished but the thread is still executing. One way to ensure that the main program exits only after the thread is finished with its

Make A More Efficient Split Function for VB4 and VB5

This is a fast, efficient way to make a split function. For longer strings, performance can be improved by enlarging AllocUnits. Public Function Split(strText As String, _Optional Byval Delimited As String = vbNullString) As Variant Const AllocUnits = 10 Dim Count As Long, startPos As Long, EndPos As Long Dim

Extract the Extension of a Filename

Extracting the extension of a filename is a requirement in many file searches and file I/O related applications. A simple way to do this is to use the split function. The following function returns the extension of the filename that is being passed to it: Function fileextension(sfilename As String) As

How to Use an Abstract Class and Define Its Abstract Methods at Instantiation

Suppose you have an abstract class MyAbstractClass with an abstract method do(): abstract class MyAbstractClass {abstract void do() ;} Of course, some classes inheriting from MyAbstractClass can be redefined with the ‘do’ method. However, it may be convenient sometime to simply redefine the abstract method at the instantiation of its

No more posts to show