static friends

Rolf Magnus ramagnus at kde.org
Thu Aug 21 21:18:17 BST 2003


On Thursday 21 August 2003 22:15, Leo Savernik wrote:
> Hello,
>
> Say I have a static function foo(), which needs access to private members
> of class bar, thus declaring:
>
> class bar {
> ...
> friend static void foo();
> };
>
> That gives the following error in gcc-2.95.2:
>
> "storage class specifiers invalid in friend function declarations"
>
> An answer to a similar posting to the gcc mailing list said to omit the
> static in the friend declaration. This compiles but issues the warning:
>
> warning: `foo()' was declared `extern' and later `static'
>
> Does this mean foo() is exported as an unresolved external in the resulting
> shared object? I really want to avoid that.

First do the normal declaration, then the friend declaration. I.e.:

static void foo();

class bar {
    friend void foo();
};




More information about the kfm-devel mailing list