I have a little c++ experience, but I still struggle with some of the syntax sometimes. I created a template class and am having some problems. The following code compiles in Visual Studio 2005 without a warning, but in Linux (and QT) it gives this error:
hist.h:14: error: expected `;' before 'listitr'
#include <list>
template <class HistClassType>
class DataHistogram
{
typedefstruct
{
HistClassType value;
int count;
} tHistValueCountPair;
public:
void blah(void)
{
std::list<tHistValueCountPair>::iterator listitr;
}
};
int main(void)
{
DataHistogram<int> hist;
}
The line in error is this: std::list<tHistValueCountPair>::iterator listitr;
if I replace it with this: std::list<tHistValueCountPair> listitr;
it compiles in Linux and Visual Studio 2005.
So it looks like the Linux compiler can handle a list of the template structure type, but not an iterator for the template structure type.
So my question is, what am I doing wrong that my Linux compiler cannot handle? I want this piece of code to be completely portable across all c++ compilers.
the two line are not the same. The second declares a variable of type std::list<tHistValueCountPair> called listitr, the first declares an iterator to a std::list<tHistValueCountPair> type.