gpt4 book ai didi

由于 std::pair,GCC (MoSync) 中的 C++ 构建错误

转载 作者:行者123 更新时间:2023-11-28 07:47:22 24 4
gpt4 key购买 nike

我正在使用 MoSync IDE 为移动平台构建我的 C++ 代码。最初,C++ 代码是由 Visual Studio 2010 单独构建的,没有任何问题。但是当我使用 MoSync IDE 重建 C++ 代码时,它生成了一些错误消息。我的 C++ 代码使用 STL 库,如 std::pair 和 std::vector 类。下面是在 MoSync IDE 中编译为错误的代码。 MoSync 使用 GCC 3.4.6。所以我假设这是由 GCC 编译器引起的。

template<typename T>
vector< pair<T, int> > histogram(const vector<T>& x, int numBins)
{
T maxVal, minVal, range, delta, leftEdge, rightEdge;
int i, dummyIdx;
vector<T>::iterator pt;
vector< pair<T, int> > counts(numBins, make_pair(T(), 0));
vector<T> y(x);

//other code ...

}

错误信息是:

错误:应为 `;'在“pt”之前(第 6 行)

此模板函数计算给定输入 vector x 和 numBins 的直方图,并返回“counts”作为 (bins, counts) 对。最初我在 Visual Studio 2010 中编译了这段 C++ 代码,没有出现任何错误。但是 MoSync IDE 中的 GCC 给了我这个错误信息。所以这让我很困惑,为什么它无法在 GCC 中构建。

最佳答案

vector<T>::iterator是依赖类型,所以你需要使用 typename :

typename vector<T>::iterator pt;

参见 Where and why do I have to put the "template" and "typename" keywords?

关于由于 std::pair,GCC (MoSync) 中的 C++ 构建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14630665/

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