Dmitri Nesteruk
Dmitri Nesteruk

Reputation: 23789

Variadic functional wrapper doesn't compile with MSVC2017

I'm attempting to compile the following with 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
  );
};

and I'm getting error C2988: unrecognizable template declaration/definition on the very first line. What am I doing wrong?

Upvotes: 0

Views: 56

Answers (1)

Jarod42
Jarod42

Reputation: 217388

You should have template <typename> struct Logger3; before your specialization.

Upvotes: 2

Related Questions