C++ vectors and typedefs...

Member
Posts: 321
Joined: 2004.10
Post: #1
typedef struct WeaponElementEntry
{
WeaponElement &we;
}
WeaponElementEntry;

typedef vector<WeaponElementEntry> VectorOfElementEntries;


The above snippet , which seems pretty straightforward to me, returns
a "expected initializer before '<' token" "VectorOfElementEntries does
not name a type"

What's the matter?

------------------------------------------------------

I even simplified the above to just this:

typedef int HeyThere;

typedef vector<HeyThere> VectorOfElementEntries;

Same error?!

Do C++ container have limitations that I'm not aware of, or is
this a stupid syntax problem?

Thanks.
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #2
Are you sure you included <vector> and 'using namespace std'?
Quote this message in a reply
Member
Posts: 321
Joined: 2004.10
Post: #3
I had the less general form

#included <vector>
using std:vector;

But "using namespace::std" fixed the problem! Needless to say I've globally
replaced all my usings with "namespace std" throughout my project. I won't
be using std::container form ever again.

Thanks!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
"using std:vector" doesn't mean anything, but "using std::vector" does mean precisely what was intended, and is much better than importing the whole namespace. They're in a namespace for a reason, so you can easily avoid clashes with your own names, even when more things are added to the standard. Don't paint yourself in for the sake of not writing a few "std::"s.
Quote this message in a reply
Moderator
Posts: 771
Joined: 2003.04
Post: #5
We really need the code to uDG entries to be made available from within iDevGames - many of these kind of questions could be answered by just browsing around in that code.

For instance:
  • use of namespaces
  • templates
  • header guards
  • loading jpgs/pngs and using them as textures
  • OpenAL/SDL_mixer/Quicktime usage

...and so on.
Quote this message in a reply
ejtttje
Unregistered
 
Post: #6
This may be old news by now, but what you needed was to add a 'typename':

Code:
typedef int HeyThere;
typedef [b]typename[/b] vector<HeyThere> VectorOfElementEntries;

You need the 'typename' whenever you are doing a typedef of a templated type.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Anybody use vectors of vector with STL? WhatMeWorry 11 8,341 Apr 27, 2005 03:39 PM
Last Post: Puzzler183