I'm trying to pass the type of a class member as a template argument. For this I'm using the following code:
class C
{
public:
int a;
};
class B
{
public:
template<typename _T> void Test() {}
// Specialize for int for Test testing purposes.
template<> void Test<int>() { printf("Success!\n"); }
};
//Later:
B b;
C c;
b.Test<decltype(c.a)>();
This gives me the following error:
error C2662: 'void B::Test(void)' : cannot convert 'this' pointer from 'C' to 'B &' Reason: cannot convert from 'C' to 'B' Conversion requires a second user-defined-conversion operator or constructor
However, it does work if I use the following code:
decltype(c.a) d;
b.Test<decltype(d)>();
Why doesn't it work if I simply use the class member directly? I'm using Visual Studio 2012.