2014-09-23 3 views
-1

요청 내 코드입니다 : 메인 파일에서C++ '회원'와 push_back '여기

void MyWork::computeDistances() 
{ 

int column = sentence1.size(); 
int row = sentence2.size(); 
//int min = 0; 

dist.resize(column); 

for (int i = 0; i < column; i++){ 
    dist[i].resize(row); 
} 

for (int i = 0; i < column; i++){ 
    for (int j = 0; j < row; j++){ 
     cout << "A" << endl; 
     if (i == 0){ 

      if (sentence1[j] == sentence2[i]){ 
       dist[i][j].push_back(0); 

, 내가 같은 2 차원 벡터를 선언 한 : 그러나

vector<vector<int> > dist; 

을, 오류가 발생합니다 :

MyWork.cpp:30:17: error: request for member ‘push_back’ in ‘(&((MyWork*)this)->MyWork::dist.std::vector<_Tp, _Alloc>::operator[] [with _Tp = std::vector<int>, _Alloc = std::allocator<std::vector<int> >, std::vector<_Tp, _Alloc>::reference = std::vector<int>&, std::vector<_Tp, _Alloc>::size_type = unsigned int](((unsigned int)i)))->std::vector<_Tp, _Alloc>::operator[] [with _Tp = int, _Alloc = std::allocator<int>, std::vector<_Tp, _Alloc>::reference = int&, std::vector<_Tp, _Alloc>::size_type = unsigned int](((unsigned int)j))’, which is of non-class type ‘int’ 

나는이 참조로 통과 함께 할 수있는 뭔가가하지만 난 잘 모르겠어요 어떻게. 도와 주셔서 감사합니다 생각!

답변

2

당신이 당신의 의견을 전달하는 방법과 관련이 없습니다.

distvector<vector<int> >

dist[i]vector<int>

dist[i][j]는 당신이 operator[]를 호출하고 int, 임. 그것은 작동하지 않습니다.

은 당신이 INT, 그것은 push_back 멤버 함수가없는 입력 한 dist[i][j] = 0;

1
dist[i][j].push_back(0); 

dist[i][j]을 원하는 생각합니다.

그것은 당신이 정말로 원하는에 따라 달라집니다

, 간단한 변화가있을 수 :

dist[i][j] = 0; 
0

당신의 정의에 따르면, DIST는 INT의 벡터의 벡터, 따라서 DIST [내가] 것은의 벡터이다 int dist [i] [j]는 int입니다. int를 푸시 백할 수 없습니다.