0

I was reading a application source and I've faced with thing like this:

class A
{

};

template<>
class B<A>
{

};

the problem is that I can't understand class B<A> meaning. What does this mean?

Hamidreza
  • 81
  • 1
  • 6
  • 6
    It's a [template specialization](https://en.cppreference.com/w/cpp/language/template_specialization) of a [class template](https://en.cppreference.com/w/cpp/language/class_template) – clcto Oct 16 '18 at 13:16
  • 1
    Do you know what a template is? – NathanOliver Oct 16 '18 at 13:16
  • The class B is a template class, probably class B has some implementation that is common to a certain type of class/objects. Look up class templates in the link http://www.cplusplus.com/doc/oldtutorial/templates/ – Shrikanth N Oct 16 '18 at 13:17
  • related/dupe: https://stackoverflow.com/questions/28354752/template-vs-template-without-brackets-whats-the-difference – NathanOliver Oct 16 '18 at 13:21
  • 2
    [This book list](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) should be your next stop. Do not learn C++ from scratch by reading source code. It may work with other languages, but here it will only lead to frustration and difficulty. – StoryTeller - Unslander Monica Oct 16 '18 at 13:26

1 Answers1

0

This means that class B has been declared as a template, and now you have a template specialization. Just like in sewing, this means that B won't work on its own, but requires another class, here A, to work.

It is a new type and then B will use A as kind of thread (to continue the sewing analogy) wherever the original type (that you didn't show) was.

You may want to have a look at https://en.cppreference.com/w/cpp/language/templates

Matthieu Brucher
  • 21,634
  • 7
  • 38
  • 62