I have a templated class A
Assuming your really meant for A::test
to be publicly accessible, you could do something like this:
#include <iostream>
template <int M>
struct ABase
{
ABase(int n) : test_( n > M )
{}
bool const test_;
};
template <typename T, int M>
struct A : ABase<M>
{
A(int n) : ABase<M>(n)
{}
};
template <typename T>
A<T, 20>::A(int n)
: ABase<20>(n)
{ std::cerr << "One type" << std::endl; }
Kick the tires:
int main(int argc, char* argv[])
{
A<int, 20> a(19);
std::cout << "a:" << a.test_ << std::endl;
A<int, 30> b(31);
std::cout << "b:" << b.test_ << std::endl;
return 0;
}