I never did template programming. What I need is the following: depending on certain integer (user input), my template should determine a type. Here is my template:
template<int T> struct abcd {};
template<>
struct abcd<6> { typedef double type_t; };
template<>
struct abcd<5> { typedef float type_t; };
template<>
struct abcd<0> { typedef unsigned char type_t; };enter code here
In certain function I want to use my template like this:
void foo(int i, int m)
{
const int j = i;
// Assume elements of A can be accessed as A.at<dataType>(location)
int a = A<abcd<j>::type_t>(m)
//do something..
}
This is showing error cannot appear in a constant-expression
. Please tell me what I am doing wrong and what can be a solution. Note that if I put const int j = 5
or any other relevant int
instead of const int j = i
, it is working fine. That is confusing me.