M
Marco Jez
Is it legal, in a class template's member function, to instantiate the same
class template but with a different type as argument? The following code is
very simple and I'd expect it to compile, but it makes both MSVC and gcc
freeze and never return. Sometimes I get an "internal compiler error"
instead.
struct Instance_base
{
virtual ~Instance_base() {}
virtual Instance_base* mkptr() = 0;
};
template<typename T>
struct Instance: Instance_base
{
T _inst;
Instance(const T &v): _inst(v) {}
Instance_base* mkptr() { return new Instance<T*>(&_inst); }
};
Instance_base* inst = new Instance<int>(3);
The offending line is that of Instance::mkptr(), if I remove it (and I make
the base class' method non-abstract) everything compiles ifne. Any clues?
Cheers,
Marco
class template but with a different type as argument? The following code is
very simple and I'd expect it to compile, but it makes both MSVC and gcc
freeze and never return. Sometimes I get an "internal compiler error"
instead.
struct Instance_base
{
virtual ~Instance_base() {}
virtual Instance_base* mkptr() = 0;
};
template<typename T>
struct Instance: Instance_base
{
T _inst;
Instance(const T &v): _inst(v) {}
Instance_base* mkptr() { return new Instance<T*>(&_inst); }
};
Instance_base* inst = new Instance<int>(3);
The offending line is that of Instance::mkptr(), if I remove it (and I make
the base class' method non-abstract) everything compiles ifne. Any clues?
Cheers,
Marco