0

The following thing is doable in C++:

#include <iostream>

using namespace std;

template <typename T>
class FooClass
{
public:
    static void bar(T t, int i)
    {
        cout << t + i;
    }
};

template<template<typename> typename target, typename ...Args>
void intermediateForClass(Args ...args)
{
    target<int>::bar(1, args...);
}



int main(int, char**)
{
    intermediateForClass<FooClass>(2);
    return 0;
}

but actually in this situation, where I only have a class with a static method, I only need a function. But I couldnt manage to do the same with functions. I thought this code would work, but it does not:

#include <iostream>

using namespace std;

template<typename T>
void foo(T t, int i)
{
    cout << t + i;
}

template<template<typename> typename target, typename ...Args>
void intermediateForFunctions(Args ... args)
{
    target<int>(1, args...);
}

int main(int, char**)
{
    intermediateForFunctions<foo>(2);
    return 0;
}

It seems that actually there is a valid type for a class template, but not for a function template. Or am I doing something wrong? Is there anyway to get the 2nd version to work? If not, why so?

Uzaku
  • 511
  • 5
  • 17
  • 2
    I assume your second example was supposed to be `intermediateForFunctions(2)` – SirGuy Aug 04 '16 at 13:12
  • 1
    You cannot refer to function templates, only functions themselves. This is just how the language works. As you saw, though, you can refer to class templates just fine. – SirGuy Aug 04 '16 at 13:14

0 Answers0