I have the following code: A derived template calling a function from a base 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 error:
In% function: In% functionmain.cpp
:void Derived<M>::bar()
: error: there are no arguments tomain.cpp:7:22
that depends on a template parameter, so a declaration offoo
must be available [-fpermissive]void bar() { foo(); }
The error correction is simple, just use foo
instead of the Base<M>::foo();
call.
My question is: Why does this error occur? Why has this restriction been imposed that I must explicitly state the base manually and that the compiler can not deduce this on its own? Why only when using templates? Is my code somewhat ambiguous?