回答編集履歴
1
追記
test
CHANGED
@@ -71,3 +71,67 @@
|
|
71
71
|
}
|
72
72
|
|
73
73
|
```
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
また、constなメンバ関数と非constなメンバ関数の両方を持つこともできます。
|
78
|
+
|
79
|
+
```C++
|
80
|
+
|
81
|
+
#include <iostream>
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
struct Spam {
|
86
|
+
|
87
|
+
void func() const {
|
88
|
+
|
89
|
+
std::cout << "const func\n";
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
void func() {
|
96
|
+
|
97
|
+
std::cout << "normal func\n";
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
};
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
int main(void) {
|
106
|
+
|
107
|
+
{
|
108
|
+
|
109
|
+
const Spam spam;
|
110
|
+
|
111
|
+
spam.func();
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
{
|
116
|
+
|
117
|
+
Spam spam;
|
118
|
+
|
119
|
+
spam.func();
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
```
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
**実行結果** [Wandbox](https://wandbox.org/permlink/Jj8qELpdd7tPwj19)
|
130
|
+
|
131
|
+
```
|
132
|
+
|
133
|
+
const func
|
134
|
+
|
135
|
+
normal func
|
136
|
+
|
137
|
+
```
|