Why can't I have a non-member function with the same name as a member function, if it also happens to take a pointer to the class?
This doesn't compile:
struct FooConfig{ int value; };
struct BarConfig{ int value; };
class Api
{
void configure(const FooConfig& cfg);
void configure(const BarConfig& cfg);
};
// helper
static void configure(Api* self, int value)
{
// Actual impl
}
void Api::configure(const FooConfig& cfg)
{
configure(this, cfg.value);
}
void Api::configure(const BarConfig& cfg)
{
configure(this, cfg.value);
}
Both Gcc and Clang are lying to me, saying that there is no function named configure that takes 2 arguments.
And here comes the funny part:
If I just rename the helper function with the self pointer, or make it take a reference instead of pointer, then it suddenly comes to existence, and all is well.
AFAIK, the coincidental resemblence to a member function isn't supposed to matter in name lookup. Am I fooling C++?