The following code looks like it should work fine, but it creates
C2738: could not deduce template argument for 'Type'.
in VS2013.
template <typename ReturnType, typename...Args>
uint GetParameterSize(ReturnType(*method)(Args...))
{
return ParameterSize<Args...>();
}
template <typename Type, typename...Remaining>
uint ParameterSize()
{
uint output = sizeof(Type);
if (sizeof...(Remaining) > 0)
{
output += ParameterSize<Remaining...>();
}
return output;
}
void MyMethod3(int a, char b, int c )
{
}
uint size = GetParameterSize(&MyMethod3);
I thought, "Oh, maybe because he has no final state." So I added:
template <typename Type>
uint ParameterSize()
{
return sizeof(Type);
}
What led to
C2668: 'ParameterSize' ambiguous call to overloaded function.
I mean, it looks quite simple, and I think it should work. How does the compiler not output arguments? I am new to variable templates, so something may be missing for me, but some of them will be appreciated. Thanks!
source
share