The online racing simulator
#1 - PoVo
[C++] ISO C++ forbids declaration of 'list' with no type
Hi,

I've been trying to set up a list variable in a C++ header file and I'm getting the error:
21|error: ISO C++ forbids declaration of 'list' with no type|

Here's the header file code:
#ifndef SERVER_H_INCLUDED
#define SERVER_H_INCLUDED

#include "definitions.h"
#include "cinsim.h"

using namespace std;

struct connection
{
char* UName;
char* PName;
byte UCID;
};

class Server
{
public:
static CInsim InSim;
[COLOR="Red"][B]static list<int> Conns;[/B][/COLOR]

static void SendTiny(byte);
};

#endif // SERVER_H_INCLUDED

The error is caused at the line with red text.

Anyone got any idea why this is so? I'm clueless at the moment.
You're not including the header required for lists... #include <list>
#3 - PoVo
Hmm, I added it and it seems working now.

But shouldn't it work without the include considering I'm using the "std" namespace and the list library is part of the "std" namespace?
"using namespace foo" isn't the same thing as including a header. When you do #include <list>, you tell the compiler to read the header file which contains the implementation of the STL List. "using namespace" is more of a convenience thing. The STL List is defined within std namespace, so if you don't have "using namespace std" if your code, you have to use "std::list" instead of "list".

BTW, is having a list of connections static a good idea here? I of course have no idea what your intentions are, but do you really want to have a common list of connections for all instances of class Server?
#5 - PoVo
I set it to static so I can access Server::Conns from every other class.

It's handy because the list will be used in pretty much every other class I have.
In that case, wouldn't it be better to make the server object global and access it like that or share a pointer to it?
#7 - PoVo
Quote from MadCatX :In that case, wouldn't it be better to make the server object global and access it like that or share a pointer to it?

I'm a complete uber nub in C++ so this was the first way that I thought of, and it worked
I see, but abusing the staticness of class members is generally considered a bad practice in any language. In C++ you might be better off doing it like this:

Option 1 - global variable (bad idea too)

--- globals.h ---
#ifndef _GLOBALS_H
#define _GLOBALS_H
#include "server.h"
extern Server serv;

#endif

--- anotherfile.h ---
#include "globals.h"
// Access serv variable


Option 2 - shared variable (much better)

--- someclass ---
#include "server.h"
Server serv;

do_something(serv);

--- another class containing do_something function ---
--- serv variable is passed by reference ---
void do_something(Server& serv)
{
// Do something with server
}


FGED GREDG RDFGDR GSFDG