[cfe-dev] Friend functions default parameters behavior

Reid Kleckner rnk at google.com
Thu Jul 24 16:16:23 PDT 2014


On Thu, Jul 24, 2014 at 2:47 PM, Александр Овчинников <sanek23994 at gmail.com>
wrote:

> Hello,
> Thanks for the answer.
>
> Can you clarify the clang description:
> As I understand we should to move definition of the function to the header
> file,  which contains declaration of the class and the friend function. Am
> I right? If so, I just think that this doesn't better way.
>

Doesn't this also work:

// declaration with default argument comes first
int func1(int i, int j = 0);

class foo {
// friend decl doesn't use default arguments
friend int func1(int i, int j);
public:
    int func();
};

int foo::func() { return func1(1); }

// implementation in .cc file
int func1(int i, int j) { return i + j; }

int main() {
    foo a;
    a.func();
    return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140724/8127c4af/attachment.html>


More information about the cfe-dev mailing list