Шаблон Variadic не компилируетсяC++

Программы на C++. Форум разработчиков
Anonymous
Шаблон Variadic не компилируется

Сообщение Anonymous »

Код: Выделить всё

#include 

template 
struct TransformFunc;

template 
class TransformFunc
{
public:
static void apply(Arg arg, Args... args)
{
func(arg, args...);
}
};

void test1(int x)
{
printf("test1: int%d\n", x);
}

void test2 (int x, float y)
{
printf("test2: int%d float%f\n", x, y);
}

int main(int, char **)
{
TransformFunc::apply(5);
TransformFunc::apply(5, 1.23f); // Error here.

return 0;
}

Код: Выделить всё

1>------ Build started: Project: main, Configuration: Debug x64 ------
1>  main.cpp
1>main.cpp(33): error C2440: 'specialization' : cannot convert from 'void (__cdecl *)(int,float)' to 'void (__cdecl *)(int)'
1>          This conversion requires a reinterpret_cast, a C-style cast or function-style cast
1>          main.cpp(33) : see reference to class template instantiation 'TransformFunc' being compiled
1>main.cpp(33): error C2973: 'TransformFunc' : invalid template argument 'void (__cdecl *)(int,float)'
1>          main.cpp(9) : see declaration of 'TransformFunc'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Я не могу понять, почему экземпляр test2 не компилируется. Есть идеи?

Подробнее здесь: https://stackoverflow.com/questions/325 ... ot-compile

Вернуться в «C++»