Friday, June 13, 2008

C++ member template function

With Visual Studio 2003 you can use member template functions, for example:

class Foo {

    template <class T> void bar(T* t) {}

};

that you can call in this way:

void main() {
  int a = 10;
  Foo obj;
  obj.bar(a);

}

Make sure that when you declare the bar method you include also the method definition otherwise you will end-up with a linker error.

Saturday, May 31, 2008