tags:

views:

94

answers:

2
+4  Q: 

Member templates

Can any one explain this

 "A using-declaration in a derived class cannot refer to a specialization 
 of a template conversion function in a base class."

it is from ISO C++ Standard ..14.5.2 ,point 7

A: 
2.)

Q: My compiler says that a member of a base class template is not defined in a derived class template. Why is it not inherited?

template<typename T>
class base {
public:
    void base_func();
};

template<typename T>
class derived : public base<T> {
public:
    void derived_func()
    {
        base_func(); // error: base_func not defined
    }
};

A: 
It is inherited. 
However, the standard says that unqualified names in a template are generally non-dependent and must be looked up when the template is defined. 
Since the definition of a dependent base class is not known at that time (there may be specialisations of the base class template that have not yet been seen), 
unqualified names are never resolved to members of the dependent base class. 
Where names in the template are supposed to refer to base class members or to indirect base classes, 
they can either be made dependent by qualifying them or brought into the template's scope with a using-declaration. 
In the example, this could be achieved by replacing the call to base_func() with this->base_func() or base<T>::base_func(), or by adding the declaration using base<T>::base_func;.

what I'm getting from this page is that to bring into a class the function from a parent templated class you have to use the using-declaration which looks like base<T>::base_func() and what the ISO standard is saying is that you cannot use a using declaration like this base<int>::base_func(). The difference is between the <>.

BT
+6  A: 

This means that this is ill-formed:

struct A { template<typename T> operator T(); };
struct B : A { using A::operator int; }; // ill-formed: refers to specialization

Likewise for other function template specializations (not only conversion functions)

struct A { template<typename T> void f(); };
struct B : A { using A::f<int>; }; // ill-formed: refers to specialization
Johannes Schaub - litb
can u explain it clearly...The 1st program is executing....but secont one is illformed..here in secone case....are u using template convertion function...
BE Student
for second program :-->error: a template-id may not appear in a using-declaration, means here it is not suitable according to this statement or not
BE Student
what about the 1st example program..it is not ill formed.....
BE Student
@BEStudent, your compiler has to reject the first snippet based on `14.5.2/7` and the second snippet based on `7.3.3/5`. Please read those sections for details.
Johannes Schaub - litb
@litb: What's the rationale behind such a restriction? In general how do we explore the reasons behind some decisions in the C++ standard?
Chubsdad
struct A { template<typename T> operator T(); };struct B : A { using A::operator int(); }; // ill-formed: refers to specialization...........is this is the program.....change int() ...or else...exactly ..same what u wrote
BE Student
I have sent a PR to clang developers: http://llvm.org/bugs/show_bug.cgi?id=7922
Johannes Schaub - litb
@chubsdad i think the best way is to ask in comp.std.c++
Johannes Schaub - litb