Re: template class constructor shall be called from the initializer
On 19 Nov., 21:24, annamalai <annamalai.gurus...@gmail.com> wrote:
list of the inheriting, non-template class constructor
On Nov 17, 1:18 am, Daniel Kr?gler <daniel.krueg...@googlemail.com>
wrote:
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).
As pointed out by Matthias Berndt, what happens when the class derives
from both A<int> and A<float>, as follows:
$ cat base.cc
template <typename T>
struct A {
A() {}
T t;
};
struct B : A<int>, A<float> {
B(): A() {} // A is A<int> or A<float>?
};
int main() { B obj; }
$
Any thoughts on this situation?
The standard already handles this situation, see
N2798, [temp.local]/4:
"A lookup that finds an injected-class-name (10.2) can
result in an ambiguity in certain cases (for example,
if it is found in more than one base class). If all of
the injected-class-names that are found refer to
specializations of the same class template, and if the
name is followed by a template-argument-list, the
reference refers to the class template itself and not a
specialization thereof, and is not ambiguous. [ Example:
template <class T> struct Base { };
template <class T> struct Derived: Base<int>, Base<char> {
typename Derived::Base b; // error: ambiguous
typename Derived::Base<double> d; // OK
};
?end example]"
Thus your example should cause an ambiguouity.
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! ]