what is relation between container class and template in C++, Can any one give me exact answer with example please thanks
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First off you must understand that C++ has three different “tiers” of named entities: Values, types, and templates. A value has a type, and objects of a certain type can take many values. (I use the terms “object”, “variable” and “named value” synonymously.) Then there are templates — templates are not types, but rather, they make types when instantiated. Templates are essentially code-generation tools (which is why templates themselves can’t be “compiled” in C++).
With that in mind, it would probably be accurate to say that libraries contain a few choice container templates, and when you instantiate one of them on some type, you get a container (class) that describes a data structure that holds elements of your type.
Basically, rather than writing a linked list for integers, and one for floats, and another one for unsigned chars, you realize that all those data structures look formally the same, and so you create one single list template, which you can then instantiate on integers, floats and unsigned chars (and perhaps a lot more!), and you always end up with the corresponding concrete container class.
I suppose the original name “standard template library” alludes to the fact that it is a collection of class templates, many of which were container templates.