Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

yanuart

I cannot use STL, why ???

This topic is 5812 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I tried to make a vector from STL, but the compiler gives me this message all the time
  
error C2143: syntax error : missing ';' before '<'
d:\game project\project code & program\engine\copy of hotgame (plp)\3dscene.h(73) : error C2501: 'vector' : missing storage-class or type specifiers
d:\game project\project code & program\engine\copy of hotgame (plp)\3dscene.h(73) : error C2059: syntax error : '<'
d:\game project\project code & program\engine\copy of hotgame (plp)\3dscene.h(73) : error C2238: unexpected token(s) preceding ';'
D3DApp.cpp
d:\game project\project code & program\engine\copy of hotgame (plp)\3dscene.h(73) : error C2143: syntax error : missing ';' before '<'
d:\game project\project code & program\engine\copy of hotgame (plp)\3dscene.h(73) : error C2501: 'vector' : missing storage-class or type specifiers
d:\game project\project code & program\engine\copy of hotgame (plp)\3dscene.h(73) : error C2059: syntax error : '<'
d:\game project\project code & program\engine\copy of hotgame (plp)\3dscene.h(73) : error C2238: unexpected token(s) preceding ';'
   
I know that I didn't make any syntax error, but why this is happening ?? This is my declaration code : vector visible_set; simple, huh ?? [edited by - Stoffel on November 22, 2002 7:14:14 PM]

Share this post


Link to post
Share on other sites
Advertisement
Missing a "using std;" or whatever it is? (using namespace std?) I don''t use namespaces much, but this looks like that could be it.

Share this post


Link to post
Share on other sites
All the standard library classes and functions are wrapped within the namespace ''std''.

To make use of anything in a namespace you have to either:

1) Already be in the namespace - if you have your own namespace, namespace yanuart { } for example, and are within the namespace scope then you won''t have problems accessing yanuart specific classes, functions etc.

2) Outside of the namspace you need to let the compiler know exactly what function, class, variable etc you want to use from the namespace. There are a few ways to do this:-

One is to explcitly qualify as the_Programmer_Goblin says. ie std::vector .
Another is to say ''using std::vector;'' somewhere before you use the vector. This shouldn''t be done in a header file, only in a cpp. You can just refer to ''std::vector'' as ''vector'' (unless there is a vector from a different namespace visible as well, then you still need to explicitly qualify as above).
Finally you can just drag everything in by saying ''using namespace std;''. Again don''t put this in a header.

Its all about stopping ambiguity for the compiler.

Share this post


Link to post
Share on other sites
if you want to make a < or > you have to type '&' followed by 'lt;' or '&' follow by 'gt;' (html for less-than and greater-than)


[edited by - petewood on November 22, 2002 6:33:19 AM]

Share this post


Link to post
Share on other sites
Put it inbetween source tags, then you get this:
( square bracket, source, close square bracket, type source stuff, square bracket, slash, source, close square bracket )

     std::vector<int> myVec      






[edited by - the_Programmer_Goblin on November 22, 2002 6:32:28 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!