Q:

Referring to a class function by the unqualified name

Suppose we have a class function like so:
class foo {
    // Private data needs to be accessed by bar
public:
    static int bar();
};

int main(int argc, char** argv) {
    // Want to write bar() instead of foo::bar()
    bar();
}

using doesn't seem to work for importing a class member into global scope, and if bar is made a global function it won't be able to access private data. Is there a way bar can be made accessible in global scope by the unqualified name?

A:

int bar()
{
    return foo::bar(); 
}

A:

That's what friends are for.
class foo {
    int i;
    // Private data needs to be accessed by bar
public:
    friend int bar(foo);
};

int bar(foo f) {
    return f.i = 3;
}

int main(int argc, char** argv) {
    foo g;
    // Want to write bar() instead of foo::bar()
    bar(g);
}

