I'm new to variadic templates in C++, so this question may seem kind of noobish to the experienced guys over here.
What im trying to do is create a proxy function
that will be able to redirect my arguments to any other function using variadic templates.
My code is as follows:
template <typename Ret, typename ... Types>
Ret proxy_function(Types ... args)
{
return MessageBoxA(args...);
}
int main(int argc, char* argv[])
{
boost::any retval = proxy_function<boost::any>(NULL, "123", "456", 0);
}
On compilation, the compiler outputs the following error:
1>Main.cpp(107): error C2664: 'int MessageBoxA(HWND,LPCSTR,LPCSTR,UINT)' : cannot convert argument 1 from 'int' to 'HWND'
However, when I supply the following code it works just fine:
template <typename Ret, typename ... Types>
Ret proxy_function(Types ... args)
{
return MessageBoxA(NULL, args...);
}
int main(int argc, char* argv[])
{
boost::any retval = proxy_function<boost::any>("123", "456", 0);
}
Is there any reason in the world why the compiler won't be able to cast it to HWND type?
And another question I have in mind right now related to this issue - Is it possible to figure out the type of arguments inside a function?
I would like to be able to do this stuff:
template <typename Ret, typename ... Types>
Ret proxy_function(Types ... args)
{
psuedo-code:
for arg in args:
do_stuff<type(arg)>(arg);
}
Thanks in advance, Aviv