gpt4 book ai didi

c++ - 标准在哪里指定类内定义的函数是内联的?

转载 作者:行者123 更新时间:2023-12-01 23:25:45 25 4
gpt4 key购买 nike

根据我的理解,类定义中定义的成员函数是隐式内联:

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 中找不到任何相关内容与简单的类定义相关(不涉及 typedef)。

我找对地方了吗?如果不是,确切的标准措辞是什么以及在哪里?

最佳答案

也许看看关于内联的部分。 🤪

[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 [..]

关于c++ - 标准在哪里指定类内定义的函数是内联的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58285629/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com