标准在哪里指定 class 内定义的函数是内联的?
Where does the standard specify that functions defined inside a class are inline?
在我的理解中,在 class 定义中定义的成员函数是隐式的 inline
:
class X {
int f() { return 1; } // Implicitly inline.
};
int g() { return 2; } // Not implicitly inline.
我一直在寻找支持这一点的标准报价,但我只能找到 basic.link/7:
In addition, a member function, static data member, a named class or enumeration of class scope, or an unnamed class or enumeration defined in a class-scope typedef declaration such that the class or enumeration has the typedef name for linkage purposes ([dcl.typedef]), has the same linkage, if any, as the name of the class of which it is a member.
我在 dcl.typedef 中找不到任何与简单 class 定义相关的内容(不涉及 typedef
)。
我找对地方了吗?如果不是,确切的标准措辞是什么?
它在 [class.mfct]:
A member function may be defined in its class definition, in which case it is an inline member function, ...
也许看看关于 inline
的部分。
[dcl.inline]/4:
A function defined within a class definition is an inline function.
这实际上在后面重复,在关于成员函数的部分(这似乎也很合理!):
[class.mfct]/1:
A member function may be defined in its class definition, in which case it is an inline member function [..]
在我的理解中,在 class 定义中定义的成员函数是隐式的 inline
:
class X {
int f() { return 1; } // Implicitly inline.
};
int g() { return 2; } // Not implicitly inline.
我一直在寻找支持这一点的标准报价,但我只能找到 basic.link/7:
In addition, a member function, static data member, a named class or enumeration of class scope, or an unnamed class or enumeration defined in a class-scope typedef declaration such that the class or enumeration has the typedef name for linkage purposes ([dcl.typedef]), has the same linkage, if any, as the name of the class of which it is a member.
我在 dcl.typedef 中找不到任何与简单 class 定义相关的内容(不涉及 typedef
)。
我找对地方了吗?如果不是,确切的标准措辞是什么?
它在 [class.mfct]:
A member function may be defined in its class definition, in which case it is an inline member function, ...
也许看看关于 inline
的部分。
[dcl.inline]/4:
A function defined within a class definition is an inline function.
这实际上在后面重复,在关于成员函数的部分(这似乎也很合理!):
[class.mfct]/1:
A member function may be defined in its class definition, in which case it is an inline member function [..]