2 years ago

#71470

test-img

zoulzubazz

Variadic template parameter expansion issue

Below is a class (with a variadic function) declaration and definition in separate files(.hpp and .cpp). Using c++14.

// in header file

class NameBuilder{
public:
  NameBuilder();
  ~NameBuilder();

  template<typename T>
  T Stitch(T lLast);

  template<typename T, typename... Args>
  T Stitch(T lFirst, Args... lArgs);
};

// in .cpp file

NameBuilder::NameBuilder() {}
NameBuilder::~NameBuilder() {}

template<typename T>
T NameBuilder::Stitch(T lLast) {
  return lLast;
}
template<typename T, typename... Args>
T NameBuilder::Stitch(T lFirst, Args... lArgs) {
  return lFirst + Stitch(lArgs...);
  }

template int NameBuilder::Stitch<int>(int);
template int NameBuilder::Stitch<int, int...>(int, int...);

// instantiation

  NameBuilder n;
  auto out = n.Stitch(1,2,3);

clang error says : Pack expansion does not contain any unexpanded parameter packs, on this line template int NameBuilder::Stitch<int, int...>(int, int...);, and the program does not compile. Having spend some time trying to get my head around this I am stuck. What is wrong here? Thanks.

c++

c++14

0 Answers

Your Answer

Accepted video resources