_base *から派生していないクラスでfooのコンストラクターを呼び出すときに、コンパイラーを叫ばせることができるようにしたいと思います。現在のコードでは、foo<_base*>自体のみが許可されています。簡単な解決策はありますか?
class _base
{
public:
// ...
};
class _derived: public _base
{
public:
// ...
};
template <typename T>
class foo
{
public:
foo () { void TEMPLATE_ERROR; }
};
template <> foo<_base*>::foo ()
{
// this is the only constructor
}
メインコード:
foo<_base*> a; // should work
foo<_derived*> b; // should work (but doesnt)
foo<int*> c; // should not work (and infact doesnt)