When using similar names in different scopes, at least one must be prefixed. Because you are implementing code inside class declarations, you must use
this
here. Imagine that the code is inline and the code block is copied as-is to the location where the function is called before compilation (replacing only the
this
pointer to the class variable name). The result would look like this:
int main(int argc, char *argv[]) {
ClassA a;
{
std::function<void (void)>
func0=[&](void) { callme(); },
func1=[&](void) { a.callme(); };
func0();
func1();
}
return 0;
}
If you would define the
runme()
function outside the class declaration, the prefix for the global scope
callme()
function must be used:
void ClassA::runme()
{
std::function<void (void)>
func0=[&](void) { ::callme(); },
func1=[&](void) { callme(); };
func0();
func1();
}