2

I can easily create template class that is friend with generic T class:

template <typename T>
class Secret {
private:
    friend T;

    Secret() {}
};

I would like to do the same, but with variadic template arguments. I want MultiSecret to be friend with each type in Ts. Is it possible to do? How can I unpack Ts?

template <typename... Ts>
class MultiSecret {
private:    
    // How to unpack Ts?

    MultiSecret() {}
};

EDIT. Secret and MultiSecret classes have private constructors. I want to allow only Ts to be able to create MultiSecret.

Aleksander Krauze
  • 3,115
  • 7
  • 18
  • 1
    Why do you need `friend` at all? I never use this keyword. – Marek R Jun 06 '22 at 14:24
  • 1
    @MarekR, you may want to look up "passkey" pattern. Having a generic Key class that is a friend of given set of classes would be nice. – Igor G Oct 30 '22 at 14:04

0 Answers0