Bay 12 Games Forum

Finally... => Creative Projects => Topic started by: narakal on February 28, 2010, 11:48:41 am

Title: quick question on STL
Post by: narakal on February 28, 2010, 11:48:41 am
OK, basically, I am using Codeblocks IDE for programming something, but while trying to use the Vector class, (by including it), compile errors show up, regarding the syntax.... From what I understand, it may be having sometihng to do with not including a stdhfx? header but I am not sure.... so....anybody have any idea how to fix?
Title: Re: quick question on STL
Post by: timmeh on February 28, 2010, 09:54:35 pm
I don't think you need to include anything besides the vector library...

Can we see some code?  It'd make it a lot easier to help you.  Maybe where you're including and using it... are you using:
Code: [Select]
using namespace std;or std:vector?  The "vector" class is in the std namespace, so you have to do or the other, like with "cout" and "cin".
Title: Re: quick question on STL
Post by: narakal on February 28, 2010, 11:16:00 pm
um....basically, I found out a little later that my problem was that vector class is not compatible with curses as is... so..... revision to original question, how does one make curses compatible with STL?
Title: Re: quick question on STL
Post by: timmeh on March 01, 2010, 08:52:28 am
I don't know what version of curses you're using, but when using PDCurses is was perfectly compatible.  I use vectors extensively in my rogue-like project, and didn't have to do anything besides including both files.

Code: [Select]
#include <string>
#include <vector>
#include <curses.h>

//Some internal includes for other class headers and such...

using namespace std;

class c_player
{
    private:
        string name;

        //Lots of other code...

        vector<string> message_log;

        vector<c_effect> effects;
    public:
        //Lots more code...
};
Title: Re: quick question on STL
Post by: narakal on March 03, 2010, 07:41:27 pm
eh.....just realized what could have been done to fix it....
Basically, when I had included headers, I included Curses before Vectors.
Thus, causing like....30 different errors..yeah. fixed it mostly now. So....lol?
Title: Re: quick question on STL
Post by: Alexhans on March 03, 2010, 08:48:43 pm
This may happen when one header you're including influences names from a standard header (like cstdio, for example).  Make sure you include the standart library headers before any other external library to avoid this kind of problems. 

It happens for example with OpenGl's Glut and cstdio.