I have a couple of template classes
template < class Cost >
class Transition {
public:
virtual Cost getCost() = 0;
};
template < class TransitionCl, class Cost >
class State {
protected:
State(){
static_assert(
std::is_base_of< Transition< Cost >, TransitionCl >::value,
"TransitionCl class in State must be derived from Transition< Cost >"
);
}
public:
virtual void apply( const TransitionCl& ) = 0;
};
and I would rather not have to pass Cost
into State
, because State
is completely independent on Cost
, but I want to ensure that TransitionCl
implements the Transition
interface.
Is there a way to make Cost
anonymous in the second template so as not to have to pass it when declaring a new State
class?
For reference, I'm using g++ -std=c++14 [source file]
EDIT: I posted a rephrased (and hopefully clearer) version of the question and received the best answer here
class StateImpl : public State< OpImpl >{ ... };
I tried to make it clear that State is an abstract class when i wrotevirtual void apply( const TransitionCl& ) = 0;
. Is there any way of doing so cleanly? – Malmo