0
votes

I'm getting this error in a header file:

error: expected initializer before ‘<’ token

class MyEntity;
typedef std::map<uint16,MyEntity*> myList_t;

I figured it's not seeing the map include, but at the top of that header file is:

#include <list>
#include <map>

In another header file:

typedef unsigned int               uint32;

Any ideas?

g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-48)

2
Are you sure this is the right line? Can you post a complete example that reproduces the error?Björn Pollex
could you please tell us, which compiler you are using, and on which platform? ThxThomas Berger
This code compiles for me, if I put the line "typedef short uint16;" in front of it. Where is your uint16 type defined at?Jeremy Friesner
Are you sure uint16 is a type? The standard types are called uint16_t etc.Kerrek SB
Try to provide a minimal complete example that still has this error. Chances are you'll find the bug yourself and if not, we'll be in a better position to help.hammar

2 Answers

1
votes

There was a macro named map that was causing a conflict.

-1
votes

In your actual code (not your simplified example) you are probably missing a ; from the end of the line before the typedef. This is usually what it means when I get that kind of cryptic error and I can almost reproduce your message by putting another underminated typedef above it:

q.cc:8: error: expected initializer before 'typedef'

My first guess was that class MyEntity was a full definition (not a forward declaration) and was missing the ; but I get a slightly different error for that.