Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "unspecialized class template can't be used as a template argument" mean?

I have a class called AbstractRManagers which i would like to inheritent from a singleton template class Singleton but the abstractRmanager needing to be a template class I have come across some strange error codes that provide no use, Ive tried looking it up but to no luck.

template <class Type>
class AbstractRManagers : public Singleton<AbstractRManagers>
{

error C3203: 'AbstractRManagers' : unspecialized class template can't be used as a template argument for template parameter 'Type', expected a real type

like image 232
Chris Condy Avatar asked Mar 02 '12 05:03

Chris Condy


People also ask

What is a template argument?

A template parameter is a special kind of parameter that can be used to pass a type as argument: just like regular function parameters can be used to pass values to a function, template parameters allow to pass also types to a function.

Can default argument be used with the template class?

Can default arguments be used with the template class? Explanation: The template class can use default arguments.

Can a template be a template parameter?

A template argument for a template template parameter is the name of a class template. When the compiler tries to find a template to match the template template argument, it only considers primary class templates. (A primary template is the template that is being specialized.)

How will you restrict the template for a specific datatype?

There are ways to restrict the types you can use inside a template you write by using specific typedefs inside your template. This will ensure that the compilation of the template specialisation for a type that does not include that particular typedef will fail, so you can selectively support/not support certain types.


1 Answers

AbstractRManagers names a template, which isn't a type -- it has to have a template parameter give to become a type. At least if I understand what you want, you probably need something like:

template <class Type>
class AbstractRManagers : public Singleton<AbstractRManagers<Type> >

...which starts to look suspiciously CRTP-like.

Then the obligatory note: chances are pretty good that you don't really need or want a singleton here (or nearly anywhere).

like image 114
Jerry Coffin Avatar answered Nov 14 '22 04:11

Jerry Coffin