1001010.com

one zero zero one zero one zero dot com
one hundred ten ten dot com
binary representation of ascii 'J' (74) dot com

home code projects photos wiki resumé tombstone ?
Individual Entry Archive: The Experiments of Jason De Arte - Evil Lawn Dart Master, Toy Maker and Professional Software Engineer
« prev: TODO: Find out if devstudio is stopped at a break point
» next: Inititializing static class members
Code | Friday
intitializing a static member of a template class
Posted by Jason on Friday September 23, 2005 09:39 AM  |  Permalink  |  Comments (0)

Note to self: the format of static template class member is
template<class T> int Test<T>::s_counter = 0;

And don't I forget it!
(what I originally forgot was the <T> - D'oH!)

// testtemplate.cpp : Defines the entry point for the console application.
#include "stdafx.h"

template <class T>
class Test
{
public:
    static int s_counter;

    Test()
    {
        s_counter++;
    }

    ~Test()
    {
        s_counter--;
    }

    static int getInstanceCount()
    {
        return s_counter;
    }
};

template<class T> int Test<T>::s_counter = 0;

int main(int argc, char* argv[])
{
    Test<long> a,b,c,d,e,f,g[3];
    printf("InstanceCount: %d\n", Test<long>::getInstanceCount());
    return 0;
}
Comments (0)

Comments are closed