Max Langhof
Max Langhof

Reputation: 23691

Where does the standard specify that functions defined inside a class are inline?

In my understanding, member functions defined inside a class definition are implicitly inline:

class X {
  int f() { return 1; } // Implicitly inline.
};
int g() { return 2; } // Not implicitly inline.

I was looking for the standard quote to support this, but I can only find 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.

I can't find anything relevant in dcl.typedef that relates to simple class definitions (without typedef being involved).

Am I looking in the right place? If not, what and where is the exact standard wording?

Upvotes: 3

Views: 104

Answers (2)

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385194

Perhaps look in the section about, well, inline. 🤪

[dcl.inline]/4: A function defined within a class definition is an inline function.

This is actually repeated later, in the section about member functions (which also seems sensible!):

[class.mfct]/1: A member function may be defined in its class definition, in which case it is an inline member function [..]

Upvotes: 5

Mark
Mark

Reputation: 1056

It's in [class.mfct]:

A member function may be defined in its class definition, in which case it is an inline member function, ...

Upvotes: 4

Related Questions