gpt4 book ai didi

涉及 vector 的 C++ 代码在 visual studio 上运行良好,但在 linux 上运行不佳

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:14:20 25 4
gpt4 key购买 nike

我正在为 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;
}
}

我遇到的错误:

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

最佳答案

你需要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();

差异不是因为平台,而是因为编译器。 typename 是必需的,但 Windows 上的编译器无论如何都接受了损坏的代码。这是 more information关于放置 typename(和 template)的位置。

关于涉及 vector 的 C++ 代码在 visual studio 上运行良好,但在 linux 上运行不佳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19252405/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com