May 1, 2001

Six Years and Counting: Developers Weigh in on the State of the Java Market

f you look at it from one perspective, the Java programming language at age six is only in first grade. On the other hand, Java’s significant strengths and large base of devoted followers mean that in many respects this versatile technology resembles more a seasoned veteran than a grade-schooler. There’s

Calling a Function Through a Pointer

The common way of calling a function through a pointer is using the pointer as if it were a function. In other words, if p is a pointer to a function called f: int f(int n){ return n;}int (*p)(int)=f; Then there’s no syntactic difference between calling f() directly, e.g., int

Calling A Template Member Function

You can define a member function that is a template in a non-template class. For example: class A{public: template void func(); // member template }; How can you call such a member function? C++ defines a special syntactic form for this: int main(){ A a; a.func < double >(); //

Introducing Generators

A generator is a function or algorithm returning a series of values upon successive calls. The most common example is a random number generator although generators have many other useful applications. For example, an application that creates temporary files must generate a unique name for each file. To accomplish this,

Converting char to wchar_t

The standard iostream family of classes defines the widen() member function which converts a single char to its wide-character equivalent. widen() has the following prototype: char_type widen(char c) const; The char_type typedef represents a system- and locale-dependent codeset of characters, e.g., Unicode. To obtain the wide-char value that corresponds to

Converting a hex String to int

In a previous tip, I showed how to convert a string containing a hexadecimal to int using the sscanf() function. stringstream objects can perform this feat too, in a more object-oriented fashion. In the following program, a string containing a hexadecimal value is converted to int by using an istringstream

Converting wchar_t to char

In addition to the widen() member function, the iostream framework supports the narrow() member function which performs the reverse operation, i.e., converting a wide character to its corresponding char value. The narrow() member function has the following prototype: char narrow(char_type c, char deflt) const; The first argument is the wide-char

Verifying a Destructor’s Invocation

Conceptually, destructors of global objects are called after main() has exited. For this reason, many debugging and memory checking tools are confused and report phantom memory leaks or warn about destructors that allegedly don’t execute. In most cases, you can ignore these false alarms. For instance, when they are reported

std::string and null Characters

Unlike C-strings, a std::string object may contain null characters in the middle of its internal buffer. For example: std::string s=

No more posts to show