I just encountered a problem with the CRTP, where I can't have the same method name (with a different signature) in both the base and derived class. The example to reproduce this issue is the following :
template <class T>
struct Base
{
void foo(){}
void bar(){
static_cast<T*>(this)->foo(1,1);
}
};
struct Derived : public Base<Derived>
{
int foo(int a,int b){ return a+b;}
};
int test()
{
Derived d;
d.bar(); // works
d.foo(1,1); // obviously works
d.foo(); // compilation error
}
I tried this under various versions of GCC, clang and even ICC using godbolt
Anybody could explain what is at work here ?
GCC output:
In function 'int test()':
22 : error: no matching function for call to 'Derived::foo()'
d.foo(); // doesn't work
^
13 : note: candidate: int Derived::foo(int, int)
int foo(int a,int b){ return a+b;}