I’ve a construct of this form:
template<class X>
struct Base
{
X get_data()
{
return X();
}
};
template<class X>
struct Derived : Base<X>
{
X do()
{
auto v = get_data();//this get is from Base
}
};
I tried to use this get as it is shown but I was getting error : there are no arguments to ‘get_data’ that depend on a template parameter, so a declaration of ‘get_data’ must be available [-fpermissive]|
Ok so I’ve tried:
X do()
{
using Base<T>::get_data;
auto v = get_data();//this get is from Base
}
And I’ve got the following error: 'Derived<T>::Base' is not a namespace. Now, here I’ve got a problem, because as a matter of fact formally Base being a struct is a namespace (special form of) but anyway, I declared using Base<T>::get_data; outside of any fnc and this compiles. So the Q is: Is that a compiler error or using ‘using declaration’ is permitted inside a fnc body?
usingdirectives for base class member names only make sense on the class level, where they serve to make names of base class members visible that might otherwise be hidden.They do not make sense at function scope, and thus aren’t allowed there.
What you can do is this:
(This is only sensible here because of your template context and the fact that
get_data()doesn’t depend on any template parameters. In an ordinary class, you wouldn’t need this at all if you aren’t deliberately hiding the function.)At function scope, the only
usingdirectives that are allowed are those that bring in names from other namespaces for the purpose of argument-dependent lookup.Also note that
dois a C++ keyword.