specialized class template point of instantiation

From: ben (benhongh_at_hotmail.com)
Date: 02/24/05


Date: Thu, 24 Feb 2005 21:13:05 +1100

In the following program, why won't member static MyTypeInfo TypeInfoBase<A>::TI be instantiated?

Ben

/////////////////////////////////

#include <list>
#include <iostream>
#include <typeinfo>

using namespace std;

list<MyTypeInfo&> ListOfTypes;

struct MyTypeInfo // purpose: to record a type
{
    type_info& tid;

    MyTypeInfo(type_info& ti)
    :tid(ti)
    {
        ListOfTypes.push_back(*this);
        cout << ti.name();
    }
};

template <typename T>
    class TypeInfoBase
    {
    private:
        TypeInfoBase();

    public:
        static typename MyTypeInfo TI;

    };

template <typename T>
    MyTypeInfo TypeInfoBase<T>::TI = MyTypeInfo(typeid(T));

template <typename T>
    class TypeTrait{};

class A
{
    //...
};

// specialize TypeTrait<A> to construct the static object
template <> class TypeTrait<A>: public TypeInfoBase<A>{};

int main(int argc, char* argv[])
{
    // TypeInfoBase<A> should have been instantiated at this point
    // and so should TypeInfoBase<A>::TI be constructed.
    // But it is not! Why??

    return 0;
}



Relevant Pages


Quantcast