PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

STL usage

Does anyone use any of the STL port containers/iterators in there PF games?

I'm trying to use slist but get the following compile errors:

Code:

D:\FMSce\Src\FMSce.cpp(777) : error C2653: 'slist<int,class _STL::allocator<int> >' : is not a class or namespace name
D:\FMSce\Src\FMSce.cpp(777) : error C2065: 'const_iterator' : undeclared identifier
D:\FMSce\Src\FMSce.cpp(777) : error C2146: syntax error : missing ';' before identifier 'it'
D:\FMSce\Src\FMSce.cpp(777) : error C2065: 'it' : undeclared identifier


I have included <slist>, and the line of code that it is complaining about is:

Code:

slist<int>::const_iterator it;


Any one any ideas?
After further investigation, i think it is because STL containers use namespace std, whereas i declare namespace Frog, but it seems i need both - is there a way to do this?

i.e, i effectivly need to do this
Code:

#include <slist>
using namespace std
#include "PocketFrog.h"
using namespace Frog;


Never really used namespace's before so sorry if this is a daft question.
Since you don't use the slist constructor on a lot of places you should declare the namespace locally, like this:
Code:
//Create two list objects
std::slist<int> list1,list2;

Then you just use the handles (list1 & list2) as usual.

The 'using namespace' command should be used with care. Its almost always best NOT to use it at all and explicitly declare the namespace like I did above. But it is very helpful sometimes. I never define the 'using namespace' globally (like PF does) but rather locally inside a function if I use it.