c++ – What does missing template argument mean?

c++ – What does missing template argument mean?

You have to say what its a collection of.

template <class A> class collection {}

requires that you use it as

collection<int> b;

or some appropriate type. That then makes a collection of ints. You havent told it what you want a collection of.

First : Instantiate template by type. So if you have template <typename obj> class T {...}; you should use it like

void main { 
  T<int> t; 
  T<bool> t1; // .. etc

You can use a template with default value for the typename parameter defined in the class template declaration

template <typename obj = int> class T {/*...*/};

void main { 
  T<> t;

but anyway you should put empty angle brackets when use it without parameter.

Second: While declaring template, place it whole in the header file. Each definition of his methods should be in the file *.h, dont ask me why, just dont split it to the header and cpp file.

Hope it helps.

c++ – What does missing template argument mean?

Well, youre missing a template argument. You cant create a collection object, thats just a template.

You can only create e.g. a collection<int> or collection<std::string>.

Leave a Reply

Your email address will not be published.