int main()
{
vector<int> myvector (3,100);
int myarray [] = { 501,502,503 };
myvector.insert (myvector.begin(), myarray, myarray+3);
return 0;
}
그건 그렇습니다.벡터 앞면에 구조를 추가하는 방법은 무엇입니까?
이되지 않습니다
typedef struct
{
float latitude;
float longitude;
} coordinate;
int main()
{
std :: vector <coordinate> previousPoints;
coordinate start;
start.latitude = 22.3;
start.longitude = 33.4;
previousPoints.insert (previousPoints.begin(), start, 1);
return 0;
}
오류 :
[email protected]:~> g++ y.cpp
y.cpp: In function ‘int main()’:
y.cpp:18:58: error: no matching function for call to ‘std::vector<coordinate>::insert(std::vector<coordinate>::iterator, coordinate&, int)’
/usr/include/c++/4.5/bits/vector.tcc:106:5: note: candidates are: std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::iterator, const value_type&) [with _Tp = coordinate, _Alloc = std::allocator<coordinate>, std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<coordinate*, std::vector<coordinate> >, typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer = coordinate*, value_type = coordinate]
/usr/include/c++/4.5/bits/stl_vector.h:858:7: note: void std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::iterator, std::vector::size_type, const value_type&) [with _Tp = coordinate, _Alloc = std::allocator<coordinate>, std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<coordinate*, std::vector<coordinate> >, typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer = coordinate*, std::vector::size_type = long unsigned int, value_type = coordinate]
[email protected]:~>
오류가 무슨 말? 두 가지 예가 다른 점은 무엇입니까?
이 오류에 대해 어리 석을 생각하지 마십시오. C++ 컴파일러 오류 메시지는 기본적으로 쓸모가 없습니다. "여기에 오류가 있지만 의미는 무엇인지 알려주지 않습니다 ... neener neener"입니다. 그들은 너무 나빠서 오류 메시지를 암호 해독하는 것만으로 생계를 유지하는 회사조차 있습니다. – 6502
@ 6502 첫 번째 줄은 확실히 말하고 있습니다 : 코드가 사용하려고 시도한 생성자가 존재하지 않는다고합니다. – juanchopanza
@juanchopanza : 진짜 재미있는 것은 다른 파일에서 const를 잊어 버리고 오류 메시지가 일반 문자보다 밑줄이 많은 이름이있는 표준 include 파일의 헛소리에서 직접 말도 안되는 것입니다. 이 특정 경우에는 오류가 ok (C++ 설정의 경우)였습니다. 하지만 좋은 오류는 "두 번째 매개 변수 앞에 누락되었습니다."... – 6502