전 포럼에서 여러 번 읽었지만 오늘 왜 내 코드에서 오류가 발생하는지 알 수 없으므로이 오류가 발생하는 이유를 지적 할 수 있습니다. 감사합니다. 나는 템플릿에 익숙하지 않고 왜 vectr이 여기에 한번 이상 선언되는지 이해하지 못합니다. 오류를 수정하기 위해 vectr을 전 세계적으로 선언하려고 시도했지만 정확한 수정이 아니라고 생각합니다. 여기 벡터 오류를 인코딩하는 런 길이 코드
main.cpp:8:31: error: invalid declarator before _v_class printContent (vector<T> v)
^
main.cpp:8:31: error: expected _)_ before _v_
main.cpp: In function _int main()_:
main.cpp:70:23: error: conflicting declaration _printContent vectr_printContent(vectr);
^
main.cpp:49:20: error: _vectr_ has a previous declaration as _std::vector<double> vectr_
vector<double> vectr;
내 코드입니다, 목표는 새로운 벡터는 기존의 벡터를 더한 항목에서 항목 수의 쌍을 가질 것이다 그래야 새로운 벡터에 길이 인코딩을 벡터의 내용을 실행하는 것입니다. 이 함수 내부에서 새로운 벡터를 생성 한 후에 새 벡터를 교환 할 것입니다.
#include <iostream>
#include "vector"
using namespace std;
template<class T>
class printContent (vector<T> v) //Error 31 here
{
vector<pair<int, T> > vp; //declare a new vector with type T
...(Here vectr would go through a loop and vp would fill up with pairs, for now I will also print out the content of the new vector here instead of swapping it out.)
}
int main()
{
vector<double> vectr; //Error 49
/*... (I fill in vectr with various numbers here, could be char or int if I declare vectr to be char or int instead)*/
printContent(vectr); //Error 70
}
귀하의 도움에 감사드립니다.
나는 사람들과 파일' "벡터"'이미 변수가 있고 기능을 추측 이름이 이미 있습니다. 이름을 변경하면 어떻게됩니까? – 0x499602D2
표준 헤더 ''또는 다른 코드로 사용되는'#include "vector"는 해당 코드도 함께 표시합니다 (다른 이름 사용을 고려하십시오). –