6
votes

Say I have a class Foo with a member function bar(). I also have a completely unrelated function which happens to be named bar() as well.

class Foo {
    /* ... */
    void bar() {
        /* ... */
    }
}

void bar() { /* ... */ }

It seems that any call to bar() from within Foo defaults to the member function.

How do I call the non-member function from inside Foo?

1

1 Answers

13
votes

Like this:

.bar();

The leading . will force the compiler to look at the module-level scope.

You can also use the fully-qualified name: module_name.bar(), where module_name is the name of the module (by default, the filename without the .d extension).