Re: About "typename" and "template".



 DEVELOP > c-Plus-Plus > Re: About "typename" and "template".

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1
Topic: DEVELOP > c-Plus-Plus
User: "Gianni Mariani"
Date: 13 Oct 2003 10:28:14 PM
Object: Re: About "typename" and "template".
Shawn Shie wrote:

Hello!
When reading source code of loki,i have some problems as below:

//HierarchyGenerators.h
namespace Private
{
...
template <>
struct GenScatterImpl<TL::Private::NoneList_ID>
{
template <class AtomicType, class MetaFunctionWrapper>
struct In
{
typedef typename
ApplyInnerType<MetaFunctionWrapper, AtomicType>::type type;
typedef type LeftBase;
typedef EmptyType RightBase;
};
};
...
}
...
template <class T, class Unit>
class GenScatterHierarchy : public Private::GenScatterImpl
<
IS_TYPELIST(T)::type_id

::template In<T, Unit>::type


{
public:
...
typedef typename Private::GenScatterImpl
~~~~~~~~(1)
<
IS_TYPELIST(T)::type_id

::template In<T, Unit>::RightBase RightBase;


~~~~~~~~ ...(2)
};
Problems:
1).Why must a "typename" in place (1)?
I ever wrote some codes with no "typename"s,
but they could be compiled exactly and worked with no error.
When must "typename" be used??

Because the standard says so.
The requirement stems from a problem in parsing because the grammer is
ambiguous so the standard just requires it to be so.


2).What's the effect of the word "template"??
There are no error without the "template" as i tried.
So, are there any semantic differences between the two--with or without
"template" ?

The use of 'template' is optional here however certain compilers (gcc)
may not recognize a template name correctly. Hence you may choose to
the template name<...> syntax to be compatible with earlier buggy versions.
see: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=795
.

 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER