I am using the CRTP and the base class has a template function. How can I use that member function in a templated derived class?
template <typename T>
struct A {
int f();
template <typename S>
int g();
};
struct B: public A<B> {
int h() { return f() + g<void>(); } // ok
};
template <typename T>
struct C: public A<C<T>> {
// must 'use' to get without qualifying with this->
using A<C<T>>::f; // ok
using A<C<T>>::g; // nope
int h() { return f() + g<void>(); } // doesn't work
};
* Edit * An earlier question, Using declaration for type-dependent template name, including the comments, suggests this isn't possible and might be an oversight in the standard.
I don't know how to solve the problem with using statement (it should look something like using A<C<T>>::template g;, but this code does not compile with my compiler). But you may call g<void> method in one of the following ways:
this->template g<void>()
A<C<T>>::template g<void>()
See the answers to this question for details about the dark side of using template keyword.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With