views:

203

answers:

4

While migrating a program from windows in linux I encountered a problem using the c++ standard template library. I am trying to typedef a template and I am getting the error 'expected initializer before '<' token on this line

typedef std::list< std::pair< int,double> > PairList;

Any ideas why this would work using mvc++ and not using g++ and how I can fix it?

A: 

Did you #include <utility> for pair?

rlbond
+2  A: 

I think this is about #includes.

The following really minimal piece of code compiles perfectly here with g++ on Linux

#include <utility>
#include <list>

typedef std::list< std::pair< int,double> > PairList;

PairList x;
Arnaud Gouder
as to why it IS working in MSVC++, I suspect its a precompiled header issue.
Jherico
Once I added the headers it worked just fine. Thanks all
DHamrick
A: 

I have had no problems with the code in G++, and generally found its STL support to be superb. Do you have all the #include directives there? Sometimes those differ from platform to platform (even when they shouldn't).

Dietrich Epp
+2  A: 

One thing to remember about standard include files is that they are allowed but not required to call each other. (It's not like they're potentially polluting the namespace by this, since they all use namespace std, which you aren't supposed to mess with.)

It is possible that, in MSVC++, includes , or vice versa, but this is not the case in the g++ headers. Therefore, a program might compile in MSVC++ and not in g++, with a required header missing in the source.

Make sure all of your required headers are actually included, and you should be fine.

David Thornley