Positions of the qualifiers 'typename' and 'template'

Positions of the qualifiers 'typename' and 'template'

Post by Sungbom Ki » Sat, 30 Mar 2002 20:31:43



In a template which takes a typename C,
if C::member is a type, we should write 'typename C::member', and
if C::member is a template, we should write 'C::template member'
and 'c.template member' where c is of type C.
Thus, 'typename' comes before 'C::' but 'template' after 'C::'.
Why does C++ have this inconsistency?

// Example:

struct C
{
     typedef int type;
     template<typename T> void nonstatic_template_func(const T*);
     template<typename T> static void static_template_func(const T*);

Quote:};

template<class C> void f()
{
     C().template nonstatic_template_func<typename C::type>(0);
     C::template static_template_func<typename C::type>(0);

Quote:}

// End example

--


      [ about comp.lang.c++.moderated. First time posters: do this! ]

 
 
 

1. Positions of the qualifiers 'typename' and 'template'

[ This is a question that I posted in comp.lang.c++.moderated ]
[ about ten days ago and got no responses to. :-)             ]
[ I guess comp.std.c++ is more appropriate for this subject.  ]

In a template which takes a class/typename C,
if C::member is a type, we should write 'typename C::member', and
if C::member is a template, we should write 'C::template member'
and 'c.template member' where c is of type C.
Thus, 'typename' comes before 'C::' but 'template' after 'C::'.
Why does C++ have this inconsistency? Just by chance or mistake?

// Example:

struct C
{
    typedef int type;
    template<typename T> void nonstatic_template_func(const T*);
    template<typename T> static void static_template_func(const T*);

template<class C> void f()
{
    C().template nonstatic_template_func<typename C::type>(0);
    C::template static_template_func<typename C::type>(0);

// End example

--

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]

[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]

2. W2K server as Internet Gateway

3. Passing 'const' as 'this' discards qualifiers

4. DEC VAX 4000/600 memory - want to buy

5. C++ templates and 'typename'

6. connecting to the ISP and a remote site...

7. Converting '->' to '.' using a template...

8. renaming fonts

9. Problems with 'template specialization' and/or 'value to type mapping'

10. 'initializing' : truncation from 'const double' to 'float' warning

11. {'a','b','\0'} not equivalent to "ab"??

12. Q:'default' before 'case' in 'switch'

13. TreeView: what's the difference btw 'child' and 'sibling'?