0

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.

tonga
  • 11,749
  • 25
  • 75
  • 96

1 Answers1

1

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?

Community
  • 1
  • 1
hmjd
  • 120,187
  • 20
  • 207
  • 252
  • This works. Thanks a lot. So why doesn't VS2010 flag this as an error while GCC considers this as an error? – tonga Jan 31 '13 at 16:46
  • @tonga: Because Visual Studio's default mode is not a strict conformance mode. TBH, I am not sure if the non-extensions mode will reject it either. – wilx Feb 01 '13 at 07:34