I would like to access a template parameter outside of a class. I usually do this as follows:
template <class T>
class A
{
typedef typename T T;
}
A<int>::T;
I would like to be able to do the same for non-type template parameters. This doesn't work:
template <int T>
class A
{
typedef typename T T;
}
A<3>::T;
I will clarify why I need this. I want to define a second class as follows:
template <class C>
class B
{
static int func() {return C::T;}
}
B<A<3> >::func();
What is the correct way to do this? Thank you very much.
That's because T
is not a type name and you cannot typedef
it. It is an int
value and, if you want to access it as a static member of the class, you need a static member int
. Seems like what you really want is this:
template <int T>
class A
{
public:
static const int x = T;
};
doSomething(A<5>::x);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With