Topic: Positions of the qualifiers 'typename' and 'template


Author: Sungbom Kim <musiphil@bawi.org>
Date: Tue, 9 Apr 2002 00:16:19 GMT
Raw View
[ 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

--
Sungbom Kim <musiphil@bawi.org>

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]