Re: template class constructor shall be called from the initializer list of the inheriting, non-template class constructor
On 16 Nov., 23:07, "Joe Smith" <unknown_kev_...@hotmail.com> wrote:
[..]
The 14882:2003(E) standard gives the following example in that section:
template <class T> struct Base {
Base* p;};
template <class T> struct Derived: public Base<T> {
typename Derived::Base* p; // meaning Derived::Base<T>
};
This does get accepted by GCC.
However, the folowing, does not:
template <class T> struct Base {
Base* p;};
struct Derived: public Base<int> {
Derived::Base* p; // meaning Derived::Base<T>
};
Is that supposed to work?
GCC rejects both it and the OP's code.
Also if either the above or OP's code is supposed to work,
then somebody really ought to file a bug report against gcc.
For a more complete answer, see my (hopefully
occurring just in time) reply to my own contribution.
In short my reading of the standard is that the OP's
usage of the shortened naming of the injected-class-name
'A' should be well-formed and well-defined (ignoring
some typos in the example and the fact that 'sometype'
wasn't declared anywhere).
[temp.local]/2 allows usage of this class-name in a
"class template specialization or partial specialization"
and by using A<int> as a base class class B is just
causing to implicitly instantiate a template specialization
of class template A, see [temp.spec]/4:
"An instantiated template specialization can be either
implicitly instantiated (14.7.1) for a given argument
list or be explicitly instantiated (14.7.2). A
specialization is a class, function, or class member that
is either instantiated or explicitly specialized (14.7.3)."
Greetings from Bremen,
Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]