Using template specialization in C++

We all know that C++ templates can be used to write generic code, e.g.   template <typename T> class Array { … };   Then we can use the same template to generate code for different template parameters.  This is called instantiation of the template.  e.g.   Array<int> x; Array<string> y;   However, sometimes we…


Using C++ Member Function Pointers

I don’t know about you, but the C++ syntax for member function pointers always eludes me.  Every time I would spend half an hour or more deciphering MSDN to get the exact syntax, only to completely forget it the next time.  Oops.   I can think of three reasons why this is happening:   The…

1

How Would You Get the Count of an Array in C++?

The question is simple: given a C++ array (e.g. x as in int x[10]), how would you get the number of elements in it?   An obvious solution is the following macro (definition 1):   #define countof( array ) ( sizeof( array )/sizeof( array[0] ) )   I cannot say this isn’t correct, because it…


Solutions to the Phraser programming challenge

On 3/29/04 I posted a programming challenge: given a telephone number, find all possible ways to represent it using English words and digits.   Several people have submitted their solutions.  This page contains a list of all the entries I received, in the order of submission.  It will be updated as I receive more solutions.   From…

8