4 basic "consumers" of an existing template #incl. subclass

Given an existing class template, [[c++timesaving Techniques]] Chapter 31 details 4 simple/basic “techniques” to use it as a consumer[1].

1) concretize and use it as a regular class. Most common and basic usage. This is how we use STL containers.
2) concretize and use it as a field of your own class. Simple composition.
3) concretize and derive from the concretized class
4) derived from the template unconcretized. You get another template. Classic extension. P678 and P684 [[absoluteC++]] explains the syntax

Other techniques not mentioned in this (beginner/intermediate) book
7) use it unconcretized as a field of your own template. Common usage of STL.
template class C7{vector v;};

8) template specialization

9) use it as a template type argument in another template. “Nested template”. P684 [[absoluteC++]]
template class C9: public multiset<vector >;

[1] Recall the distinction between a library codebase and a consumer codebase. A regular function or class we write can a consumer or part of some library. A class template is always in a library.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s