3

I have this code:

  template<char ...T>
  class base
  {
       std::array<uint8_t, ID_SIZE> m_ID = { Ts... };
  }

  template<char ...T>
  class derived: public base<T>
  {
       // this class doesn;t need to know anything about T
  }

when I compile this code, I am getting this error:

  'T': parameter pack must be expanded in this context  

What is this error and how i can fix it?

3
  • 1
    You have to unpack the pack: class derived: public base<T...> Commented Dec 12, 2017 at 12:42
  • How do you expand the parameter pack in the base class (or in the derived class for that matter)? Have you tried something like that? Commented Dec 12, 2017 at 12:42
  • @Someprogrammerdude add code that shows how data was unpacked. Commented Dec 12, 2017 at 12:47

2 Answers 2

2

Multiple template parameters (type or non-type) cannot be passed as packs but have to be unpacked each time:

template<char ...T>
class base { }

template<char ...T>
class derived: public base<T...> // unpack
{      
}

Inside of base<> the parameters will then be re-packed in the context of T.

Sign up to request clarification or add additional context in comments.

Comments

2

T is not one type, it is the name of a "parameter pack."

base<T> is nonsensical, because base requires a list of types, not a pack of types. base<T...> will unpack the types and work as you expect.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.