void square(vector<int> &v)
vector 内の各整数を 2 乗する関数を呼び出す関数を作成するように依頼されましたv
。これが私が持っているものですが、コンパイラエラーが発生し続けます。与えられた助けは大歓迎です
#include<iostream>
#include<vector>
#include<string>
using namespace std;
void square(vector<int> &v)
{
for(int i=0; i<v.size(); i++){
v = v[i]*v[i];
}
}
ここに私のコンプエラーがあります:
'void square(std::vector<int>&)':
editor.cpp:11:13: error: no match for 'operator=' in 'v = ((& v)->std::vector<_Tp, _Alloc>::operator[]<int, std::allocator<int> >(((std::vector<int>::size_type)i)) * (& v)->std::vector<_Tp, _Alloc>::operator[]<int, std::allocator<int> >(((std::vector<int>::size_type)i)))'
editor.cpp:11:13: note: candidate is:
In file included from /usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/vector:70:0,
from editor.cpp:3:
/usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/bits/vector.tcc:161:5: note: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]
/usr/lib64/gcc/x86_64-slackware-linux/4.7.1/../../../../include/c++/4.7.1/bits/vector.tcc:161:5: note: no known conversion for argument 1 from 'int' to 'const std::vector<int>&'