가 다음 오류 생성C++ <벡터 <vector int>>
int main() {
mat_int mat1(5, vector<int>{1,2,3});
mat_int mat2(5, vector<int>{4,5,6});
for (auto it1 = mat1.begin(); it1 != mat1.end() ; ++it1) {
for (auto it11 = *it1.begin(); it11 != *it1.end(); it11++)
cout << *it11;
cout << '\n';
}
}
컴파일러는 내부 루프 반복자를 허용하지 않는다 /home/asabbah/programming/C++/vectors1.cpp:16:28 : 오류 : '클래스 __gnu_cxx :: __ normal_iterator의 *, 표준 : : 벡터>>'I 경우,
그러나 '시작'라는 이름의 회원이 없습니다 임시 변수를 삽입 : 다음
vector<int> temp = *it1;
:
for (auto it11 = temp.begin(); it11 != temp.end(); it11++);
모든 것이 잘 간다.
이유는 무엇입니까? 부재 액세스 연산자 .
는 역 참조 연산자*
보다 higher priority 있기 때문에
[* 연산자 우선 순위 *] (http://en.cppreference.com/w/cpp/language/operator_precedence) 문제입니다. 예를 들어보십시오. 대신 it1-> begin()'또는'(* it1) .begin()'을 사용하십시오. –
['using namespace std;'는 나쁜 습관입니다.] (https://stackoverflow.com/q/1452721/2176813) 절대 사용하지 마십시오. – tambre