我正在使用MoSync IDE为移动平台构建C++代码。最初,C++代码是由Visual 2010单独构建的,没有任何问题。但是当我使用MoSync IDE重新构建C++代码时,它会产生一些错误消息。我的C++代码使用std::结对和std::向量类这样的STL库。下面是在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行)
该模板函数计算给定输入向量x和numBins的直方图,并返回“计数”作为对(桶,计数)。最初,我在Visual 2010中编译了此C++代码,没有任何错误。但是GCC在MoSync IDE中给了我这个错误信息。所以这让我很困惑,为什么这不能在GCC身上建立起来。
发布于 2013-01-31 16:39:33
vector<T>::iterator是依赖类型,因此您需要使用typename
typename vector<T>::iterator pt;请参阅Where and why do I have to put the "template" and "typename" keywords?
https://stackoverflow.com/questions/14630665
复制相似问题