Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: ANSI C++ St...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 5 Topic 6666 of 9983
Post > Topic >>

Re: ANSI C++ Standard

by "Alf P. Steinbach" <alfps@[EMAIL PROTECTED] > Feb 20, 2006 at 06:32 PM

* mdlinux7@[EMAIL PROTECTED]
> Best way to get inside C++ is to read C++ standards. Inspite of four
> years of experience, I get confused reading C++ standard.
> 
> I could not understand the below paragraph $14.2
> 
> Note: in a class template declaration, if the declarator-id is  a
> template-id, the  declaration  declares  a  class  template  partial
> specialization
> 
> A template specialization (_temp.spec_) can be referred to by  a
> template-id:
> 
> How could we justify the $14.2 paragraph in below example
> template<class T1, class T2, int I> class A             { }; // #1
> template<class T, int I>            class A<T, T*, I>   { }; // #2
> partial specialization
> 
> What will be declaration-id in above case ?

First of all, you're really discussing §14/2 (second paragraph of main 
section fourteen), not §14.2.

For a declaration of a class without any template stuff involved, the 
'declarator-id' is just the (possibly qualified) class name, and in the 
case above it's what plays the role of that simple class name, namely 
the 'A<T,T*,I>'.

> As per my understanding, template-id will be class A<T,T*,I>.

No, it will be just 'A<T,T*,I>'.

Shown here in a more usenet-friendly notation than the standard's, 
'declarator-id' is defined by §8/4 as

   declarator-id ::= id-expression
   declarator-id ::= "::"(opt) nested-name-specified(opt) type-name

'id-expression' is defined by §5.1/1 as

   id-expression ::= unqualified-id
   id-expression ::= qualified-id

'qualified-id' is defined by §5.1/7 as (I imply line continuation by \)

   qualified-id  ::= "::"(opt) nested-name-specifier "template"(opt) \
                     unqualified-id
   qualified-id  ::= identifier
   qualified-id  ::= operator-function-id
   qualified-id  ::= template-id

Interestingly, 'template-id' is defined by §14.2  --  the place you 
indicated but not what you actually referred to!  --  as

   template-id   ::= template-name "<" template-argument-list(opt) ">"

Summing up so far,

   declarator-id ::= id-expression ::= qualified-id ::= template-id

That's the connection between 'declarator-id' and 'template-id', and to 
find the 'declarator-id' part of a declaration you'll have to nest in 
the opposite direction from §8.4's definition, namely the context a 
'declarator-id' can appear in, the role it plays in a class declaration 
(as I explained first of all, informally).  Btw., I have found that to 
search in Adobe Acrobat, it's a good idea to leave out hyphens.  E.g., 
search for 'declaratorid' instead of searching for 'declarator-id'.


> It gets difficult to understand keywords like declaration-id in C++
> standard. Is there any better way to understand C++ standards

It might be useful to buy a book on templates.  As I understand it 
Josuttis wrote a good one.  Also, see my search tip above.


> as I want to get hold of each line quoted in standards.

?

-- 
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 5 Posts in Topic:
ANSI C++ Standard
mdlinux7@[EMAIL PROTECTED  2006-02-20 11:24:32 
Re: ANSI C++ Standard
"Alf P. Steinbach&qu  2006-02-20 18:32:12 
Re: ANSI C++ Standard
Chris Hills <chris@[EM  2006-02-20 19:01:31 
Re: ANSI C++ Standard
mdlinux7@[EMAIL PROTECTED  2006-02-22 20:33:22 
Re: ANSI C++ Standard
Jerry Coffin <jcoffin@  2006-02-23 06:08:05 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Sep 6 15:43:59 CDT 2008.