I am a beginner of C++. I am learning ADL (Augments Dependent Lookup).
In my understanding, virtual_function_with_EnumInBase(B<T>::EnumInBase e)
at line (1) can be looked up by ADL with B<T>::EnumInBase
.
However gcc 4.9.2 gives me error message:
virtual_function_with_EnumInBase
was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation.
If someone knows the reason why it could not lookup the function or notices my misunderstanding, please tell me it. Thank you very much.
template<typename T>
class B {
public:
virtual ~B() = default;
enum EnumInBase { e0 = 0, e1 = 1 };
virtual void virtual_function_with_EnumInBase(EnumInBase e) {
std::cout << "B::virtual_function_with_EnumInBase(EnumInBase e)" << std::endl;
}
};
template<typename T>
class D : public B<T> {
public:
virtual ~D() = default;
void virtual_function_test(void) {
typename B<T>::EnumInBase val_for_lookup = B<T>::e0;
virtual_function_with_EnumInBase(val_for_lookup); // line (1)
}
};
void test(void) {
D<double> a;
a.virtual_function_test();
}