Re: template template parameters and base class names
On 1 Mai, 02:00, rog...@howzatt.demon.co.uk wrote:
Should the code compile? I am uncertain.
No, the code should not compile, explanations v.i.
8X------------------------
class Normal {};
template <class TypeImpl>
class Policy1
{};
template <class> class Templ {};
template <template <class> class Policy>
class TemplTempl
{};
class Derived1 : public Normal
{
Normal works;
Templ<Normal> works_too;
};
class Derived2 : public Policy1<char>
{
Policy1<int> works;
TemplTempl<Policy1> fails; // << !!
This should not compile, because according to
14.6.1/1 Policy1 is an injected-class-name that
is equivalent to the injected-class-name
Policy1<char> (in this situation). Due to this
"expansion" it's understandable that
TemplTempl<Policy1> fails;
essentially means
TemplTempl<Policy1<char> > fails;
which would cause the same compile error
you observe.
The above interpretation is effectively disabled by
using a qualified name, see e.g. para 2c,
"When the normal name of the template (i.e., the name
from the enclosing scope, not the injected-classname)
is used without a template-argument-list, it refers to the
class template itself and not a specialization of the
template."
and therefore
TemplTempl< ::Policy1> works_too;
compiles.
TemplTempl<::Policy1> works_too;};
This should *not* compile, because <: is
a so-called alternative token (corresponding to
'[') which would lead to the (invalid) C++ code
interpretation of
TemplTempl[:Policy1> works_too;
Since you argue that it compiled, you probably
have actually tested
TemplTempl< ::Policy1> works_too;
where the space between < and : is required.
Greetings from Bremen,
Daniel Kr?gler
---
[ 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.comeaucomputing.com/csc/faq.html ]