回答編集履歴
1
update
answer
CHANGED
@@ -7,4 +7,13 @@
|
|
7
7
|
};
|
8
8
|
```
|
9
9
|
|
10
|
-
Demo: [https://wandbox.org/permlink/KE2Y3rrXjRdKwxjA](https://wandbox.org/permlink/KE2Y3rrXjRdKwxjA)
|
10
|
+
Demo: [https://wandbox.org/permlink/KE2Y3rrXjRdKwxjA](https://wandbox.org/permlink/KE2Y3rrXjRdKwxjA)
|
11
|
+
|
12
|
+
---
|
13
|
+
**追記:** 上記コードはGCCで通りますが、Clangではエラーになります。
|
14
|
+
|
15
|
+
StackOverflowに同じトピック"[Can I implement an autonomous `self` member type in C++?](http://stackoverflow.com/questions/21143835/)"があり、どうもC++14(C++1z/17でも?)現在は実現不可能な気がしてきました。
|
16
|
+
|
17
|
+
C++14(N3937) [expr.prim.general]/paragraph 3によれば、`this`キーワードをstaticメンバ関数の宣言中で用いるのはNGと読めます(太字部)。C++1z/17(N4659)では[expr.prim.this]/p2。
|
18
|
+
|
19
|
+
> If a declaration declares a member function or member function template of a class `X`, the expression `this` is a prvalue of type "pointer to __cv-qualifier-seq__ `X`" [...] It shall not appear before the optional __cv-qualifier-seq__ and **it shall not appear within the declaration of a static member function** (although its type and value category are defined within a static member function as they are within a non-static member function). [...]
|