Topic: ambiguity in multiple template base classes, where can I find some information in C++ the standard?
Author: uvts_cvs@yahoo.com
Date: Thu, 4 Oct 2007 14:42:30 CST Raw View
Hi all,
I have tried to look for some info related to template base classes in
the standard but with no luck.
May you please give me some hints?
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.
Thank you very much.
Alessandro
template < class T >
class A
{
public:
void foo( void ) {}
};
class B
: public A< int >
, public A< double >
{
void bar( void )
{
A::foo(); //ambiguos
}
};
---
[ 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 ]
Author: =?iso-8859-1?q?Daniel_Kr=FCgler?= <daniel.kruegler@googlemail.com>
Date: Thu, 4 Oct 2007 16:47:55 CST Raw View
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 ]
Author: uvts_cvs@yahoo.com
Date: Fri, 5 Oct 2007 03:11:55 CST Raw View
On 5 Oct, 00:47, Daniel Kr gler <daniel.krueg...@googlemail.com>
wrote:
> 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?
Microsoft Visual Studio 2005
I submitted a bug here:
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=302803
ambiguity not detected in a class derived from template classes
> The standard is pretty clear here
> in 14882-2003, 14.6.1|[temp.local]/2b:
Thank you very much for your help!
I had access only to the 1998 edition of the standard and it doesn't
include the example you quoted.
>
>
>
> > 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?
The comment is my own expectation.
>
> You can simply fix this problem by proper qualification
> to A<double>::foo() or A<int>::foo() depending on your
> intends.
Yes, thank you.
>
> Greetings from Bremen,
Greetings from Italy
>
> Daniel Kr gler
Alessandro Gentilini
---
[ 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 ]