Reputation: 1
So my instructor handed out some code that I believe does not work at all and I want to get some clarification on it. He used this in his hand out notes (it implies that this is correct).
template<class T>
class State
{
public:
virtual void Enter(T*)=0;
virtual void Execute(T*)=0;
virtual void Exit(T*)=0;
virtual ~State(){};
};
I can see what he is trying to do but I believe the compiler will not like it at all. Can anyone help explain why this does or does not work.
Upvotes: 0
Views: 1558
Reputation: 1447
This should work as none of the member functions are not template member functions. The base class arguments can be deduced at compile-time, and the actual function to call can still be determined at runtime.
If you had this:
class Foo
{
template< typename T > virtual void Bar( T * ) = 0;
};
You would have problems as there is no way to generate functions to handle all the potential types that may be passed into this function at compile time.
Upvotes: 2