3
I have the following code: A derivative template calling a base function also template.
template <int M>
struct Base { void foo() {} };
template <int M>
struct Derived : public Base<M> {
void bar() { foo(); }
};
But this causes the following mistake:
main.cpp
: In Member Functionvoid Derived<M>::bar()
:
main.cpp:7:22
: error: there are no Arguments tofoo
that Depend on a template Parameter, so a declaration offoo
must be available [-fpermissive]void bar() { foo(); }
Error correction is simple, just use Base<M>::foo();
in place of the foo()
.
My question is: Why this error occurs? Why was this restriction imposed that I must clarify the basis manually and that the compiler cannot deduce this on its own? Why only when using templates? My code is somehow ambiguous?