views:

142

answers:

4

I just reorganized the code for a project and now I'm getting errors I can't resolve. This header is included by a .cpp file trying to compile.

#include "WinMain.h"
#include "numDefs.h"
#include <bitset>

class Entity
{
public:
    Entity();
    virtual ~Entity();

    virtual bitset<MAX_SPRITE_PIXELS> getBitMask();
    virtual void getMapSection(float x, float y, int w, int h, bitset<MAX_SPRITE_PIXELS>* section);
};

I'm getting these compiler errors for the declaration of Entity::getBitMask():

error C2143: syntax error : missing ';' before '<'

error C2433: 'Entity::bitset' : 'virtual' not permitted on data declarations

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

error C2238: unexpected token(s) preceding ';'

There are more similar errors for the next line as well. It seems like bitset isn't getting included but it clearly is? I can't figure out what's going wrong. WinMain.h includes windows.h, and numDefs.h includes nothing.

Using MS Visual C++ 2008.

A: 

Looks like an error in "numDefs.h"

Martin York
+7  A: 

Declare the bitset as std::bitset<MAX_SPRITE_PIXELS>.

MSN
+5  A: 

The bitset template is defined in the std:: namespace, so you either need to reference it by it's full name std::bitset or add using namespace std; somewhere before the class declaration.

sth
"add using namespace std; somewhere" but not in a header file
TimW
Where is the best place to do this? I'm only using one namespace, so should I just put "using namespace std;" before the #includes in all my cpp files?
Tony R
How did you do it till now? I would recommend to just write the std:: prefix when you use things from the standard library. Otherwise you end up with lot's of things with very common names (like "copy") in your global namespace that you don't even know about. This can lead to surprising effects. Otherwise it's probably best to use the fully qualified names in the headers and do the "using namespace std;" at the top of your .cpps, after the #includes.
sth
+4  A: 

I think you need to say std::bitset.

Eric H.