Is there a way to specify that a template parameter type must be derived from a particular base class? This is how I wish it would work:
class foo
{
a_foo_function() const;
};
//.......
template < class F : public foo > // <<<=== my deceptively creative syntax
class bar
{
F * pfd;
bar(F* food){ pfd = food; }
void f() const { pfd->a_foo_function(); } //guaranteed to work in my book
};
//.......
class foo just_a_plain_foo;
//.......
class foodish : public foo {} a_foodish;
//.......
class foolish : public not_foo {} a_foolish;
//.......
class foodous : public foodish {} a_foodous;
//.......
typedef bar<foodish> barf;
barf a(a_foodish); //ok
barf b(a_foodous); //ok
barf c(a_foolish); //NOT ok ... foolish is not derived from foo
barf d(just_a_plain_foo); //NOT ok ... pfd pointer is to derived foodish
Ain't that beautiful? But my beautiful syntax won't compile, though; and I can't seem to find how to do this. Note that using the base class as template parameter won't work for me, as I may have distinct and mutually incompatible classes deriving from foo. TIA.