Is a friend function defined in-class automatically inline?

前端 未结 1 421
渐次进展
渐次进展 2021-01-18 01:07

If a member function is defined inside the class, it is an inline function. E.g.

struct X
{
   void mem_f() {} //mem_f is inline
};

My ques

1条回答
  •  盖世英雄少女心
    2021-01-18 01:54

    Yes, it is. §11.4/5:

    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. A friend function defined in a class is in the (lexical) scope of the class in which it is defined. A friend function defined outside the class is not (3.4.1).

    Since the class definition is presumably in a header file, the function will be multiply-defined, so it needs to be inline.

    0 讨论(0)
提交回复
热议问题