65 lines
2.3 KiB
Markdown
65 lines
2.3 KiB
Markdown
[class.mfct]
|
||
|
||
# 11 Classes [[class]](./#class)
|
||
|
||
## 11.4 Class members [[class.mem]](class.mem#class.mfct)
|
||
|
||
### 11.4.2 Member functions [class.mfct]
|
||
|
||
[1](#1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L1059)
|
||
|
||
If a member function is attached to the global module and is defined ([[dcl.fct.def]](dcl.fct.def "9.6 Function definitions")) in its class definition,
|
||
it is inline ([[dcl.inline]](dcl.inline "9.2.8 The inline specifier"))[.](#1.sentence-1)
|
||
|
||
[*Note [1](#note-1)*:
|
||
|
||
A member function is also inline if it is declaredinline, constexpr, or consteval[.](#1.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
[2](#2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L1069)
|
||
|
||
[*Example [1](#example-1)*: struct X {typedef int T; static T count; void f(T);};void X::f(T t = count) { }
|
||
|
||
The definition of the member function f of class X inhabits the global
|
||
scope; the notation X::f indicates that the function f is a member of class X and in the scope of class X[.](#2.sentence-1)
|
||
|
||
In
|
||
the function definition, the parameter type T refers to the
|
||
typedef member T declared in class X and the default
|
||
argument count refers to the static data member count declared in class X[.](#2.sentence-2)
|
||
|
||
â *end example*]
|
||
|
||
[3](#3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L1090)
|
||
|
||
Member functions of a local class shall be defined inline in their class
|
||
definition, if they are defined at all[.](#3.sentence-1)
|
||
|
||
[4](#4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L1095)
|
||
|
||
[*Note [2](#note-2)*:
|
||
|
||
A member function can be declared (but not defined) using a typedef for
|
||
a function type[.](#4.sentence-1)
|
||
|
||
The resulting member function has exactly the same type
|
||
as it would have if the function declarator were provided explicitly,
|
||
see [[dcl.fct]](dcl.fct "9.3.4.6 Functions") and [[temp.arg]](temp.arg "13.4 Template arguments")[.](#4.sentence-2)
|
||
|
||
[*Example [2](#example-2)*: typedef void fv();typedef void fvc() const;struct S { fv memfunc1; // equivalent to: void memfunc1();void memfunc2();
|
||
fvc memfunc3; // equivalent to: void memfunc3() const;};
|
||
fv S::* pmfv1 = &S::memfunc1;
|
||
fv S::* pmfv2 = &S::memfunc2;
|
||
fvc S::* pmfv3 = &S::memfunc3; â *end example*]
|
||
|
||
â *end note*]
|