0

After reading this thread, I wrote down:

template <typename T, template <T> typename C> class Base

Base class contains a 'C' type container that contains 'T' type objects.

My problem is when I try to make a derived class:

class Derived : public Base

The first error was

argument list for class template is missing.

So I figured I have to tell the template Base class what types I'm gonna use. So suppose my derived class will have a 'std::set' for container that has integers.

class Derived : public Base <int, set<int>>

But it 'std::set<int>' gets underlined in red and it tells me it's "not a template class".

I'm not sure to understand what I'm doing wrong.

Thanks in advance.

max66
  • 65,235
  • 10
  • 71
  • 111
  • Your either need to qualify your template template class correctly, or provide a variadic solution (which is doable). Either will work. – WhozCraig Apr 07 '18 at 01:42
  • What your IDE marks as an error is far less important then actual compile errors. Post the full compiler error in your question. – super Apr 07 '18 at 02:13

1 Answers1

1

template typename C> class Base

Base class contains a 'C' type container that contains 'T' type objects.

Not in the sense that C is a container like std::set. I mean: C doesn't receive a template type parameter as STL containers.

With your Base you can write

template <int>
struct foo
 { };

template <typename T, template <T> typename C>
class Base
 { };

class Derived : public Base <int, foo>
 { };

where foo receive a integer, not a type.

If you want a std::set as second parameter, you can write

template <typename T, template <typename...> typename C>
class Base
 { };

where C receive a variadic list of types (std::set receive three template type parameters; the second and the third are defaulted).

So you can write

class Derived : public Base <int, std::set>
 { };

Another way is write Base as receiving a single type and use partial specialization to resolve container and container template paramenter

template <typename>
class Base;

template <template <typename...> typename C, typename A0, typename ... As>
class Base<C<A0, As...>>
 { };

so you can pass directly the type std::set<int> (with defaulted template types) as follows

class Derived : public Base <std::set<int>>
 { };
max66
  • 65,235
  • 10
  • 71
  • 111