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 3 1671
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
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
Barry schrieb:
Well, good example
Thanks! :D
but the /clumsy use/ of rebind is:
Allocator:: template rebind<Node>::o ther
Well, even worse. But seems you got the point. ;)
Frank This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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() {}
|
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 to turn a previously
made String class that deals with char's into a templated String class
that uses the template parameter C instead of char. I thought it would
be fairly simple to do this exercise, but I encoutered many errors for
my...
|
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 base
of them all.
Because I don't know what classes I am dealing with, I try to get
a reference to the base class. Since the base class is a template
instaniation, I cannot find a common type for all classes that
|
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 return. I tried to write something like
this:
template <class Type1, class Type2, class Type3>
Type3 findMin(Type1 x, Type2 y){
return (x < y) ? x : y;
|
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
internal interactive debugger that knows the classes
within our system and allow us to walk around the objects that exist
at the time of the fault. It mostly works fairly well. That catch
being that we have to hand implement some of the code...
| |
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, 1> and A<int, 2> are different types. Now, if the A template
|
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 an embedded environment with multiple processors. I
created a policy for classes, which, I had hoped, would automatically
register the class with the appropriate factory:
// In some header file...
#include <cassert>
|
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 trying to hide the `complexity` of template from the
user interface. If you look at the code DataSet should be the object
that my user manipulate. Unfortunately by doing so the object returned
by DataSet::Get is a FloatingPt, so without the virtual...
|
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 to check. What I
expected was that there would be minor code bloat and some speed
improvement when using templates. However...
I wrote a basic list container (using templates), and a list container
(using virtual derived classes). I also tried...
|
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 .
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |