template<class T>
class A {
T t;
public:
void foo(){ t.foo(); }
};
class B {
public:
virtualvoid foo() = 0;
};
class C : public B {
public:
void foo();
};
class D {
};
A<C> ac; // ok
A<D> ad; // error
So I want the "T" in class "A" to be inherited from "B" so that it can use the "foo" function. There'd be an error since there's no foo function in class D but the message is kind of cryptic.
I could do some sort of assert in the constructor yah? Wouldn't help with any error messages unless it manages to compile somehow.
1 2 3 4
A()
{
assert( dynamic_cast<B*>(&t) != NULL );
}
I need to pass it as a template though since it needs to be able to construct/destruct the class. Otherwise ne555 I would do that. Thanks for the help.