Variadic功能包装器不能用MSVC2017编译

时间:2017-09-07 08:20:35

标签: c++ variadic-templates variadic-functions

我试图用VS2017编译以下内容:

template <typename R, typename ...Args>
struct Logger3<R(Args...)>
{
  std::function<R(Args...)> func;
  string name;

  Logger3(std::function<R(Args...)> func, const string& name)
    : func{func}, name{name}
  {
  }

  R operator() (Args ...args)
  {
    cout << "Entering " << name << endl;
    R result = func(args...);
    cout << "Exiting " << name << endl;
    return result;
  }
};

double add(double a, double b)
{
  cout << a << " + " << b << " = " << (a+b) << endl;
  return a+b;
}

template <typename R, typename... Args>
auto make_logger3(R (*func)(Args...), const string& name)
{
  return Logger3<R(Args...)>(
    std::function<R(Args...)>(func),
    name
  );
};

我在第一行收到error C2988: unrecognizable template declaration/definition。我做错了什么?

1 个答案:

答案 0 :(得分:2)

在专业化之前,你应该有template <typename> struct Logger3;