涉及矢量的C++代码在visual studio上工作得很好,而不是在linux上工作

Gar*_*ngh 1 c++ linux vector visual-studio-2008

我正在为MRI扫描仪编码,基本要求是任何序列代码都应该在visual studio和linux上运行.

我有一部分代码可以在visual studio 2008上正常工作; 但是,在linux上给我错误.

有人可以告诉我,我做错了什么?

template<typename type1, typename type2, typename type3>
void PrintVector3(type1 VectorIn_1, type2 VectorIn_2, type3 VectorIn_3) {   

    type1::const_iterator  i1 = VectorIn_1.begin(); 
    type2::const_iterator  i2 = VectorIn_2.begin();  
    type3::const_iterator  i3 = VectorIn_3.begin(); 
    int lLenghtVec = VectorIn_1.n_elem();

    for(int i = 0; i != lLenghtVec; ++i){
        std::cout << std::setfill('0') << std::setw(3) << *i1 << "      " << *i2 << "      "  << *i3 <<std::endl;
        ++i3; ++i2; ++i1;
    }
}
Run Code Online (Sandbox Code Playgroud)

我得到的错误:

CESTiPAT/ReorderInfo_DK.h:185: error: expected ';' before 'i1'
CESTiPAT/ReorderInfo_DK.h:186: error: expected ';' before 'i2'
CESTiPAT/ReorderInfo_DK.h:187: error: expected ';' before 'i3'
CESTiPAT/ReorderInfo_DK.h:191: error: 'i1' was not declared in this scope
CESTiPAT/ReorderInfo_DK.h:191: error: 'i2' was not declared in this scope
CESTiPAT/ReorderInfo_DK.h:191: error: 'i3' was not declared in this scope
Run Code Online (Sandbox Code Playgroud)

Dan*_*rey 7

你需要typename:

typename type1::const_iterator  i1 = VectorIn_1.begin(); 
typename type2::const_iterator  i2 = VectorIn_2.begin();  
typename type3::const_iterator  i3 = VectorIn_3.begin(); 
Run Code Online (Sandbox Code Playgroud)

差异不是因为平台,而是因为编译器.这typename是必需的,但是Windows上的编译器仍接受破坏的代码.以下是有关放置typename(和template)的位置的更多信息.