简短的回答是“你没有”。
一种使您想做的事情变得容易的randomA
方法N=1
(const TransitionMatrixTemplate<N, M> randomA()
对N=1
.
template<typename D, int N, int M, int K>
struct Bob_Base {
static_assert( std::is_base_of< D, Bob_Base<D, N, M, K> >::value, "D must be derived from Bob_Base" );
D* self() { return static_cast<D*>(this);
D const* self() const { return static_cast<D*>(this);
const TransitionMatrixTemplate<N, M> randomA()
{
// use self()-> instead of this-> in here to access Bob methods and date
}
};
template<typename D,int M, int K>
struct Bob_Base< D, 1, M, K > {
static_assert( std::is_base_of< D, Bob_Base<D, N, M, K> >::value, "D must be derived from Bob_Base" );
D* self() { return static_cast<D*>(this);
D const* self() const { return static_cast<D*>(this);
const TransitionMatrixTemplate<1, M> randomA()
{ /* N=1 version */ }
};
template<int N, int M, int K>
struct Bob : Bob_Base<Bob<N, M, K>, N, M, K>
{
//lots of stuff, but no TransitionMatrixTemplate
}
这仅在无法编译的代码(反之亦然)时才重要。N==1