質問編集履歴

4

エラー文追加

2020/07/06 06:43

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -76,11 +76,11 @@
76
76
 
77
77
  /***/main.cpp: In function ‘int main()’:
78
78
 
79
- /***/main.cpp:16:13: error: no matching function for call to ‘func(std::vector<int>&)’
79
+ /***/main.cpp:16:18: error: no matching function for call to ‘func(std::vector<int>&)’
80
-
80
+
81
- func(vec);
81
+ func(left_ref);//左辺値
82
-
82
+
83
- ^
83
+ ^
84
84
 
85
85
  /***/main.cpp:5:6: note: candidate: template<class Vec, class Type> void func(Vec&&)
86
86
 
@@ -90,9 +90,31 @@
90
90
 
91
91
  /***/main.cpp:5:6: note: template argument deduction/substitution failed:
92
92
 
93
- /***/main.cpp:16:13: note: couldn't deduce template parameter ‘Type’
93
+ /***/main.cpp:16:18: note: couldn't deduce template parameter ‘Type’
94
-
94
+
95
- func(vec);
95
+ func(left_ref);//左辺値
96
+
97
+ ^
98
+
99
+ /***/main.cpp:18:39: error: no matching function for call to ‘func(std::vector<int>)’
100
+
101
+ func(std::vector<int>{{1,2,3,4,5}});//右辺値
102
+
103
+ ^
104
+
105
+ /***/main.cpp:5:6: note: candidate: template<class Vec, class Type> void func(Vec&&)
106
+
107
+ void func(Vec<Type>&& vec){
108
+
109
+ ^~~~
110
+
111
+ /***/main.cpp:5:6: note: template argument deduction/substitution failed:
112
+
113
+ /***/main.cpp:18:39: note: couldn't deduce template parameter ‘Type’
114
+
115
+ func(std::vector<int>{{1,2,3,4,5}});//右辺値
116
+
117
+
96
118
 
97
119
 
98
120
 

3

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

2020/07/06 06:43

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -48,9 +48,13 @@
48
48
 
49
49
  {
50
50
 
51
- std::vector<int> vec = {1,2,3,4,5};
51
+ std::vector<int> left_ref = {1,2,3,4,5};
52
-
52
+
53
- func(vec);
53
+ func(left_ref);//左辺値
54
+
55
+
56
+
57
+ func(std::vector<int>{{1,2,3,4,5}});//右辺値
54
58
 
55
59
  return 0;
56
60
 
@@ -186,8 +190,6 @@
186
190
 
187
191
 
188
192
 
189
-
190
-
191
193
  func(std::vector<int>{{1,2,3,4,5}});//右辺値
192
194
 
193
195
  return 0;

2

追加

2020/07/06 06:40

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  そのvectorの要素の型と同じ変数varを作り
6
6
 
7
- その関数内部で作成したvectorにコピー/ムーブ
7
+ その新たに作成したvectorにコピー/ムーブ
8
8
 
9
9
  したあとそれらを使って
10
10
 

1

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

2020/07/06 06:34

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -4,6 +4,10 @@
4
4
 
5
5
  そのvectorの要素の型と同じ変数varを作り
6
6
 
7
+ その関数内部で作成したvectorにコピー/ムーブ
8
+
9
+ したあとそれらを使って
10
+
7
11
  処理を行う関数を作りたいのですが
8
12
 
9
13
  エラーが発生してしまいます。