devxlogo

May 1, 2001

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

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

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

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

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.

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

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=