specialized class template point of instantiation
From: ben (benhongh_at_hotmail.com)
Date: 02/24/05
- Next message: Sharon Gorev: "Re: Assertion error when using Free (non-local pointer)"
- Previous message: Anders Eriksson: "Re: BigInt lib not working, help!"
- Next in thread: Victor Bazarov: "Re: specialized class template point of instantiation"
- Reply: Victor Bazarov: "Re: specialized class template point of instantiation"
- Reply: Tom Widmer: "Re: specialized class template point of instantiation"
- Messages sorted by: [ date ] [ thread ]
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;
}
- Next message: Sharon Gorev: "Re: Assertion error when using Free (non-local pointer)"
- Previous message: Anders Eriksson: "Re: BigInt lib not working, help!"
- Next in thread: Victor Bazarov: "Re: specialized class template point of instantiation"
- Reply: Victor Bazarov: "Re: specialized class template point of instantiation"
- Reply: Tom Widmer: "Re: specialized class template point of instantiation"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|