Zizheng Tai
Zizheng Tai

Reputation: 6636

Inline friend function defined in class body

Normally when we define a member function directly in the class body, it is implicitly inline. But what about this:

class Foo {
public:
    friend void swap(Foo& a, Foo& b) { ... }

    ...
};

Is the swap implicitly inline or not?

Upvotes: 1

Views: 860

Answers (1)

aschepler
aschepler

Reputation: 72431

Yes. See [class.friend/6-7] from the Standard:

A function can be defined in a friend declaration of a class if and only if the class is a non-local class (9.8), the function name is unqualified, and the function has namespace scope.

Such a function is implicitly inline.

Upvotes: 5

Related Questions