2010-12-13 3 views
2

첫 번째 템플릿 클래스는 compressed_matrix에서 PETSc Sparse AIJ 형식으로 단순화 된 변환기를 사용하려고하지만 처음부터 iterator typedef declerations에 문제가 있습니다. 그래서 T는 compressed_matrix입니다. 아래의 코드를 사용하면 순식간에 컴파일 타임 오류가 발생합니다. 대신이 반복자를 어떻게 정의해야합니까? 나는템플릿 유형이 템플릿 자체 일 경우 반복자를 얻는 방법은 무엇입니까?

template <class T, class T1> 
int converter<T, T1>::convertMBo2Pe(const T& A, 
          T1 A_){ 
    PetscErrorCode ierr; 
    int cntNnz = 0; 
    typedef T::iterator1 i1_t; 
    typedef T::iterator2 i2_t; 
    //int nnz[ooFelieMatrix.size1()]; 
    int nnz[A.size1()]; 
    unsigned ind=0; 
    //get information about the matrix 

    double* vals = NULL; 
    for (i1_t i1 = A.begin1(); i1 != A.end1(); ++i1) 
    { 
     nnz[ind] = distance(i1.begin(), i1.end()); 
     ind++; 
    } 
    // create the matrix depending 
    // on the values of the nonzeros 
    // on each row 
    ierr = MatCreateSeqAIJ(PETSC_COMM_SELF, A.size1(), 
                A.size2(), cntNnz, nnz, 
                A_); 
    PetscInt rInd = 0, cInd=0; 
    PetscInt* rCount, dummy; 
    rCount = &dummy; 
    // pointer to values in a row 
    PetscScalar* valsOfRowI = NULL; 
    PetscInt* colIndexOfRowI = NULL; 
    PetscInt rC = 1; 
    for(i1_t i1 = A.begin1(); i1 != A.end1(); ++i1) 
    { 
     // allocate space for the values of row I 
     valsOfRowI  = new PetscScalar[nnz[rInd]]; 
     colIndexOfRowI = new PetscInt[nnz[rInd]]; 
     for(i2_t i2 = i1.begin(); i2 != i1.end(); ++i2) 
     { 
     colIndexOfRowI[cInd] = i2.index2(); 
     valsOfRowI[cInd]  = *i2; 
     cInd++; 
     } 
     // setting one row each time 
     *rCount = rInd; 
     MatSetValues(A_, rC, rCount, nnz[rInd], 
            colIndexOfRowI, valsOfRowI, 
        INSERT_VALUES); 
     // delete 
     delete [] valsOfRowI; 
     delete [] colIndexOfRowI; 
     rInd++; cInd = 0; 
    } 
    // 
    MatAssemblyBegin(A_, MAT_FINAL_ASSEMBLY); 
    MatAssemblyEnd(A_, MAT_FINAL_ASSEMBLY); 
    // return 
    return 0; 
} 

답변

1

당신은 (그 라인을 따라 정적 변수, 또는 무언가에 반대) 명시 적으로 T::iterator1는 유형 이름이고 컴파일러에게이 ...이 템플릿에 대한 자세한 아마도 조금 읽어야합니다.

typedef typename T::iterator1 i1_t;

+0

사실 그러나 이것은 단지 파일 헤더이며 전혀 컴파일되지 않으며, 템플릿 기능이 PETSc 라이브러리 함수에 연결이 필요합니다 BTW, 정보에 대한보다 근본적인 문제 들으있을 것 같습니다. 그래서 템플릿을위한 별도의 구현 및 헤더 파일 전략 같은 해결 방법이 있습니다. –

관련 문제