質問するログイン新規登録

質問編集履歴

4

エラー文追加

2020/07/06 06:43

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -37,16 +37,27 @@
37
37
  void func(Vec<Type>&& vec){
38
38
  ^~~
39
39
  /***/main.cpp: In function ‘int main()’:
40
- /***/main.cpp:16:13: error: no matching function for call to ‘func(std::vector<int>&)’
40
+ /***/main.cpp:16:18: error: no matching function for call to ‘func(std::vector<int>&)’
41
- func(vec);
41
+ func(left_ref);//左辺値
42
- ^
42
+ ^
43
43
  /***/main.cpp:5:6: note: candidate: template<class Vec, class Type> void func(Vec&&)
44
44
  void func(Vec<Type>&& vec){
45
45
  ^~~~
46
46
  /***/main.cpp:5:6: note: template argument deduction/substitution failed:
47
- /***/main.cpp:16:13: note: couldn't deduce template parameter ‘Type’
47
+ /***/main.cpp:16:18: note: couldn't deduce template parameter ‘Type’
48
- func(vec);
48
+ func(left_ref);//左辺値
49
+ ^
50
+ /***/main.cpp:18:39: error: no matching function for call to ‘func(std::vector<int>)’
51
+ func(std::vector<int>{{1,2,3,4,5}});//右辺値
52
+ ^
53
+ /***/main.cpp:5:6: note: candidate: template<class Vec, class Type> void func(Vec&&)
54
+ void func(Vec<Type>&& vec){
55
+ ^~~~
56
+ /***/main.cpp:5:6: note: template argument deduction/substitution failed:
57
+ /***/main.cpp:18:39: note: couldn't deduce template parameter ‘Type’
58
+ func(std::vector<int>{{1,2,3,4,5}});//右辺値
49
59
 
60
+
50
61
  ```
51
62
  エラー内容は
52
63
 

3

わかりやすくなるよう追加

2020/07/06 06:43

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -23,8 +23,10 @@
23
23
 
24
24
  int main(void)
25
25
  {
26
- std::vector<int> vec = {1,2,3,4,5};
26
+ std::vector<int> left_ref = {1,2,3,4,5};
27
- func(vec);
27
+ func(left_ref);//左辺値
28
+
29
+ func(std::vector<int>{{1,2,3,4,5}});//右辺値
28
30
  return 0;
29
31
  }
30
32
 
@@ -92,7 +94,6 @@
92
94
  std::vector<int> left_ref = {1,2,3,4,5};
93
95
  func(left_ref);//左辺値
94
96
 
95
-
96
97
  func(std::vector<int>{{1,2,3,4,5}});//右辺値
97
98
  return 0;
98
99
  }

2

追加

2020/07/06 06:40

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,7 +1,7 @@
1
1
  ### 質問内容
2
2
  std::vectorをユニバーサル参照で受け取り
3
3
  そのvectorの要素の型と同じ変数varを作り
4
- その関数内部で作成したvectorにコピー/ムーブ
4
+ その新たに作成したvectorにコピー/ムーブ
5
5
  したあとそれらを使って
6
6
  処理を行う関数を作りたいのですが
7
7
  エラーが発生してしまいます。

1

わかりやすくするため質問内容部分に追加

2020/07/06 06:34

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,6 +1,8 @@
1
1
  ### 質問内容
2
2
  std::vectorをユニバーサル参照で受け取り
3
3
  そのvectorの要素の型と同じ変数varを作り
4
+ その関数内部で作成したvectorにコピー/ムーブ
5
+ したあとそれらを使って
4
6
  処理を行う関数を作りたいのですが
5
7
  エラーが発生してしまいます。
6
8
  どうすればvector内の要素の型を取得できますか。