I wondering is there any way to set restrictions on template class?
Specify that every type substituted in template must have specific ancestor (realize some interface).
template < class B > //and every B must be a child of abstract C
class A {
public:
B * obj;
int f() {
return B::x + this->obj->f();
}
};
Like => in haskell
func :: (Ord a, Show b) => a -> b -> c
You can use
BOOST_STATIC_ASSERTor a similar library to assert your restrictions on the template parameter.For example:
EDIT: For your example, you can write