回答編集履歴
3
コンストラクタなしのコード追記
answer
CHANGED
@@ -35,6 +35,19 @@
|
|
35
35
|
1.5,1
|
36
36
|
```
|
37
37
|
|
38
|
+
---
|
39
|
+
`Point`にコンストラクタを追加しなくても、
|
40
|
+
|
41
|
+
```diff
|
42
|
+
-return Point<decltype(a.x* b)>(a.x * b, a.y * b);
|
43
|
+
+return Point<decltype(a.x* b)>{a.x * b, a.y * b};
|
44
|
+
-std::cout << Point<int>(3, 2) * 0.5 << std::endl;
|
45
|
+
+std::cout << Point<int>{3, 2} * 0.5 << std::endl;
|
46
|
+
```
|
47
|
+
とすればコンパイル可能です。
|
48
|
+
|
49
|
+
---
|
50
|
+
|
38
51
|
> decltypeを使うメリット
|
39
52
|
|
40
53
|
以下のリンク先「この機能が必要になった背景・経緯」を参照して下さい。
|
2
decltype追記
answer
CHANGED
@@ -33,4 +33,10 @@
|
|
33
33
|
結果
|
34
34
|
```
|
35
35
|
1.5,1
|
36
|
-
```
|
36
|
+
```
|
37
|
+
|
38
|
+
> decltypeを使うメリット
|
39
|
+
|
40
|
+
以下のリンク先「この機能が必要になった背景・経緯」を参照して下さい。
|
41
|
+
[decltype](https://cpprefjp.github.io/lang/cpp11/decltype.html)
|
42
|
+
[戻り値の型を後置する関数宣言構文](https://cpprefjp.github.io/lang/cpp11/trailing_return_types.html)
|
1
文言修正
answer
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
[ここ](http://yohshiy.blog.fc2.com/blog-entry-334.html)の「decltype の活用」でしょうか?
|
2
|
-
問題なく動作しましたが…
|
2
|
+
(コンストラクタとシフト演算子を追加すれば)問題なく動作しましたが…
|
3
3
|
```C++
|
4
4
|
#include <iostream>
|
5
5
|
template <typename T>
|