I am writing some c++ template code to replace if-else conditions in present source. Here, I am deriving Helper data type based on two conditions, 1. isAdvice 2. SimpleOrComplex
See below template code:
template<bool isAdvice, class SH, class CH>
class IfThenElse;
template<class SH, class CH>
class IfThenElse<true, SH, CH>
{
public:
typedef SH Helper;
};
template<class SH, class CH>
class IfThenElse<false, SH, CH>
{
public:
typedef CH Helper;
};
template <bool isAdvice, bool SimpleOrComplex>
class DeriveHelper
{
public:
typedef typename IfThenElse<isAdvice,
IfThenElse<SimpleOrComplex, SimpleHelper, ComplexHelper>::Helper,
IfThenElse<SimpleOrComplex, SimpleNoAdvHelper, ComplexNoAdvHelper>::Helper>::Helper DerivedHelper;
};
However, Getting this error at compilation:
template.cpp:135: error: type/value mismatch at argument 2 in template parameter list for 'template<bool isTradeAdvice, class SH, class GH> struct IfThenElse'
template.cpp:135: error: expected a type, got 'IfThenElse::Helper'
template.cpp:135: error: type/value mismatch at argument 3 in template parameter list for 'template<bool isTradeAdvice, class SH, class GH> struct IfThenElse'
template.cpp:135: error: expected a type, got 'IfThenElse::Helper'
Can someone please suggest the reason?