473,396 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

template template classes

Could someone please explain template template classes, showing:

1). Why they are needed / i.e what problem do they solve ?
2). A simple example

I have read various articles etc, but it still dosen't seem to make
sense to me

Sep 3 '07 #1
3 1654
Anonymous wrote:
Could someone please explain template template classes, showing:

1). Why they are needed / i.e what problem do they solve ?

template <class T, class Container>
class Stack1;

template <class T, template <classclass Container>
class Stack2

with Stack1, the template parameter Container needs container class
with Stack2, Container is a template template parameter, it need a class
with *one* template parameter.

see the usage:

class Vector1; // holds int

template <class T>
class Vector2;

Stack1<int, Vector1s1;
Stack1<int, Vector2<int s2;

Stack2<int, Vector1s3; // compile time error
Stack2<int, Vector2<int s4;

so template template parameter restrict the parameter you pass into the
template class.
Any other use, I don't know.

Anyway it's not mandatory, in STL, as far as I know, there's no template
template parameter usage.
2). A simple example

I have read various articles etc, but it still dosen't seem to make
sense to me

--
Thanks
Barry
Sep 3 '07 #2
Barry wrote:
Anonymous wrote:
>Could someone please explain template template classes, showing:

1). Why they are needed / i.e what problem do they solve ?


template <class T, class Container>
class Stack1;

template <class T, template <classclass Container>
class Stack2

with Stack1, the template parameter Container needs container class
with Stack2, Container is a template template parameter, it need a class
with *one* template parameter.

see the usage:

class Vector1; // holds int

template <class T>
class Vector2;

Stack1<int, Vector1s1;
Stack1<int, Vector2<int s2;

Stack2<int, Vector1s3; // compile time error
Stack2<int, Vector2<int s4;
My bad,
Stack2<int, Vector2s4;
>
so template template parameter restrict the parameter you pass into the
template class.
Any other use, I don't know.

Anyway it's not mandatory, in STL, as far as I know, there's no template
template parameter usage.
>2). A simple example

I have read various articles etc, but it still dosen't seem to make
sense to me


--
Thanks
Barry
Sep 3 '07 #3
Barry schrieb:
Well, good example
Thanks! :D
but the /clumsy use/ of rebind is:

Allocator:: template rebind<Node>::other
Well, even worse. But seems you got the point. ;)

Frank
Sep 4 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Sebastian Faust | last post by:
Hi, is a construction like the following possible: template<class view_model> class template_clase { protected: template_clase() {} virtual ~template_clase() {}
1
by: Oplec | last post by:
Hi, I'm learning C++ as a hobby using The C++ Programming Language : Special Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that deal with templates. Exercise 13.9 asks for me...
2
by: Agent Mulder | last post by:
Hi group, I try to get a reference to a template. In the template, a virtual function is declared. Later in the program, I inherit from classes created by the template. So the template is the...
31
by: nikola | last post by:
Hi all, I was working with a simple function template to find the min of two values. But since I would like the two values to be different (type) I dont know what kind of value (type) it will...
0
by: Chris F Clark | last post by:
In our C++ project we have some internal bug reporting macros that we use to get useful information when the program does something unexpected. Essentially at the point of the error, we invoke an...
8
by: Tony Johansson | last post by:
Hello Experts! What does this mean actually. If you have a template with a type and non-type template argument, say, like this template<typename T, int a> class Array {. . .}; then A<int,...
12
by: mlimber | last post by:
This is a repost (with slight modifications) from comp.lang.c++.moderated in an effort to get some response. I am using Loki's Factory as presented in _Modern C++ Design_ for message passing in...
7
by: mathieu | last post by:
Hello, I did read the FAQ on template(*), since I could not find an answer to my current issue I am posting here. I have tried to summarize my issue in the following code (**). Basically I am...
45
by: charles.lobo | last post by:
Hi, I have recently begun using templates in C++ and have found it to be quite useful. However, hearing stories of code bloat and assorted problems I decided to write a couple of small programs...
7
by: Amu | last post by:
Hi i am stuck up in a part of project where i have to inherit the VC++ template classes into C#.net. Please provide me the solution for this .
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.