Re: ambiguity in multiple template base classes, where can I find some information in C++ the standard?
On 4 Okt., 22:42, uvts_...@yahoo.com wrote:
The following code compiles well with my compiler but leads to an
unexpected run-time behaviour and so I would like to know what (and
where :-) the standard says about multiple template base classes.
Which compiler does accept this? The standard is pretty clear here
in 14882-2003, 14.6.1|[temp.local]/2b:
"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
};"
Actually the below described problem is only little related
to templates, but more to derived classes as the above
redirection to [class.member.lookup] points out.
template < class T >
class A
{
public:
void foo( void ) {}
};
class B
: public A< int >
, public A< double >
{
void bar( void )
{
A::foo(); //ambiguos
}
};
I don't understand, why you above say that the compiler
does accept the code but the program causes a run-time
error compared to above comment. Or is this comment
your own expectation?
You can simply fix this problem by proper qualification
to A<double>::foo() or A<int>::foo() depending on your
intends.
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 ]