0

The following code does not compile. Is there a different syntax to achieve that?

template <typename T>
struct A {};

template <typename T>
struct B {};

template <typename S, typename T>
struct C : S<T> {};  // unknown template name 'S'

int main() {
  A<int> a;
  B<int> b;
  C<A,int> c; // Use of class template 'A' requires template arguments
}
fatdragon
  • 2,211
  • 4
  • 26
  • 43
  • `template – cigien Aug 18 '21 at 00:06
  • *"Is there a different syntax to achieve that?"* -- this is a pretty weak description of your problem, relying on others inferring your intent from your non-working code. (Your title is even worse, ending with a preposition that lacks an object.) Better questions pose their questions as text rather than as code. You are trying to ask if there is a syntax that will allow you to pass the name of a template as a template parameter, right? Not that hard to describe with words, is it? (If you did that, I might judge this question better written than the first duplicate.) – JaMiT Aug 18 '21 at 01:11

1 Answers1

2

The C struct template needs to use a "template template parameter"

template <typename T>
struct A {};

template <typename T>
struct B {};

template <template<typename> typename S, typename T>
struct C : S<T> {};  

int main() {
    A<int> a;
    B<int> b;
    C<A, int> c; // Use of class template 'A' requires template arguments
}
jwezorek
  • 8,592
  • 1
  • 29
  • 46