Re: [C++] Question on Templates (Vandevoorde & Josuttis)
From: Ulrich Eckhardt (doomster_at_knuut.de)
Date: 12/23/04
- Next message: Lawrence Kirby: "Re: Learning C with Older books ?."
- Previous message: James Dennett: "Re: #include <all> [Was Re: novice: small annoyance]"
- Next in thread: B. v Ingen Schenau: "Re: [C++] Question on Templates (Vandevoorde & Josuttis)"
- Reply: B. v Ingen Schenau: "Re: [C++] Question on Templates (Vandevoorde & Josuttis)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 23 Dec 2004 19:10:21 +0100
entropy123 wrote:
> Hi all,
>
> My question is related to 'Using Templates in Practice' section 6 of
> C++ Templates: Vandevoorde & Josuttis. I'm having trouble with the
> implementation of 'The Inclusion Model' for a class template. The
> example given by the authors is for a function template:
>
>>>From pg 62: The header file for the 'Inclusion Model':
>
> //declaration of template
> template <typename T>
> void print_typeof(T const&);
>
> //implementation/definition of template
> template <typename T>
> void print_typeof(T const& x);
Here the problems start: this is just a declaration, too!? I think you
either missed something or there is a mistake in the book. Check the
errata.
> As opposed to the 'Explicit Model:
>
> //explicity instantiate print_typeof() for type double
> template void print_typeof<double>(double const&);
If there was a definition of print_typeof in scope, this would instantiate
it for type double.
> Here is my header file for the 'inclusion model' database template. It
> does not compile and generates syntax errors along the line of " inT
> unidentified identifier" and so on:
>
> //InclusionBase.h
> template< typename T > class Base; //forward declaration
> template< typename T> class Base {}; //Base Template
> template <typename T> Base< T inT>; //?Implicit?
^^^^^
What is the 'inT' supposed to mean there anyway? Sorry, but this syntax is
simply wrong. Please reread and try the examples in V&J first, before you
start modifying them.
> What do I need to do to implement an 'inclusion model' class template?
> Its just fine to explicitly define some of the derived classes, but I
> really would like to be able to allow Base<Datum> and Base<Type> to be
> replaced by something more generic....
>
> Please let me know if I need to clear anything up to get this question
> answered....
It might be interesting to know what exactly an 'inclusion model' is in
this context; I've never come across this term.
Uli
-- FAQ: http://ma.rtij.nl/acllc-c++.FAQ.html
- Next message: Lawrence Kirby: "Re: Learning C with Older books ?."
- Previous message: James Dennett: "Re: #include <all> [Was Re: novice: small annoyance]"
- Next in thread: B. v Ingen Schenau: "Re: [C++] Question on Templates (Vandevoorde & Josuttis)"
- Reply: B. v Ingen Schenau: "Re: [C++] Question on Templates (Vandevoorde & Josuttis)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|