I'm using MoSync IDE to build my C++ code for mobile platform. Initially the C++ code was built separately by Visual Studio 2010 without any problems. But when I used MoSync IDE to rebuild the C++ code, it generated some error message. My C++ code uses STL library like std::pair and std::vector classes. Below is the code that was compiled as error in MoSync IDE. MoSync uses GCC 3.4.6. So I assume this is caused by the GCC compiler.
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 ...
}
The error message is:
error: expected `;' before "pt" (line 6)
This template function calculates histogram given the input vector x and numBins, and it returns "counts" as the pair of (bins, counts). Originally I compiled this C++ code in Visual Studio 2010 without any errors. But GCC in MoSync IDE gave me this error message. So this baffles me a lot why this fails to build in GCC.
vector<T>::iterator
is dependent type so you need to use typename
:
typename vector<T>::iterator pt;
See Where and why do I have to put the "template" and "typename" keywords?