Spoon wrote:
> Hello,
>
> Consider the following code:
>
> int foo(int n) { return n+2; }
>
> class bar
> {
> public:
> int x;
> bar() { x = 42; }
> int foo() { return foo(x); }
> };
>
> int main()
> {
> bar baz;
> return baz.foo();
> }
>
> Apparently this doesn't work.
Ok, but lets be clear. AFAIK, the reason it doesn't work is not
because it is a global function in the unnamed namespace. It is
because it is a global function in the unnamed namespace with the same
name as a function in your class. If you had a global function that
did not have the same name as a name in your class then you could refer
to it without using the :: qualifier.
Another solution, not mentioned yet, is to put both your class and your
utility functions in the same namespace and then you can refer to the
utility functions without a qualifier. Again if there is a name
conflict you will need to qualify the function name but at least your
function would not be in the global namespace and in normal cases you
would not need to qualify it.
---
Ivan
http://www.0x4849.net