Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Template+Dependent Name

Tags:

c++

templates

$14.6.2/3 - "In the definition of a class template or a member of a class template, if a base class of the class template depends on a template-parameter, the base class scope is not examined during unqualified name lookup either at the point of definition of the class template or member or during an instantiation of the class template or member."

As per this, the call 'f(0)' in 'D::g' should call 'B:f'. However gcc(IdeOne) gives an ambiguit error.

Is this a bug in gcc? Comeau compiles it fine

template<class T, class U> struct A{
   template<class A, class B> A f(B b){A a; return a;}
};

struct B{
   double f(double d){return 0.0;}
};

template<class T, class U> struct D : A<T, U>, B{
   void g(){f(0);}
};

int main(){
   D<double, double> d;
   d.g();
}
like image 486
Chubsdad Avatar asked Sep 10 '10 12:09

Chubsdad


People also ask

What is dependent name example?

A dependent name is a name that depends on the type or the value of a template parameter. For example: template<class T> class U : A<T> { typename T::B x; void f(A<T>& y) { *y++; } }; The dependent names in this example are the base class A<T> , the type name T::B , and the variable y .

Which is Dependant on template parameter?

Which is dependant on template parameter? Explanation: Base class is dependant on template parameter.

What is type name in template?

" typename " is a keyword in the C++ programming language used when writing templates. It is used for specifying that a dependent name in a template definition or declaration is a type.

What is dependent type in C++?

A function whose type of return value varies with its argument (i.e. there is no fixed codomain) is a dependent function and the type of this function is called dependent product type, pi-type (Π type) or dependent function type.


1 Answers

I think it is a known bug in GCC. According to the bug report, your example fails as late as GCC 4.4.0. I think that just means it hasn't been tested on a newer version though - not that it's been fixed.

like image 68
Michael Kristofik Avatar answered Sep 22 '22 13:09

Michael Kristofik