By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,045 Members | 1,305 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,045 IT Pros & Developers. It's quick & easy.

bitfields as static members?

P: n/a
Hello,

I'm attempting to define a class that has a bitfield as a static
member. The definition seems ok, but I'm at a loss as to how to declare
it:

class Test {
static struct TestBitFields {
unsigned int Flag1:1;
unsigned int Flag2:1;
} BitFields;
};

Thanks in advance!

Apr 14 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a

TedKennedyMurderedHisPregnantMistress.dwp...@spamg ourmet.com wrote:
Hello,

I'm attempting to define a class that has a bitfield as a static
member. The definition seems ok, but I'm at a loss as to how to declare
it:

class Test {
static struct TestBitFields {
unsigned int Flag1:1;
unsigned int Flag2:1;
} BitFields;
};

Thanks in advance!


Er, please ignore the ommission of "public". :-)

Apr 14 '06 #2

P: n/a
Te**********************************...mg ourmet.com wrote:
I'm attempting to define a class that has a bitfield as a static
member. The definition seems ok, but I'm at a loss as to how to
declare it:

class Test {
static struct TestBitFields {
unsigned int Flag1:1;
unsigned int Flag2:1;
} BitFields;
};


I think you got those things in reverse. You already declared the
struct and the member. Now you need to define it:

class Test {
...
};

Test::TestBitFields Test::BitFields;

V
--
Please remove capital As from my address when replying by mail
Apr 14 '06 #3

P: n/a

Victor Bazarov wrote:
Te**********************************...mg ourmet.com wrote:
I'm attempting to define a class that has a bitfield as a static
member. The definition seems ok, but I'm at a loss as to how to
declare it:

class Test {
static struct TestBitFields {
unsigned int Flag1:1;
unsigned int Flag2:1;
} BitFields;
};
I think you got those things in reverse. You already declared the
struct and the member. Now you need to define it:


Duh, you're right. Thanks for pointing out my oversight!
class Test {
...
};

Test::TestBitFields Test::BitFields;


Works like a charm; thanks. Even got initialization going. :-)

Apr 14 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.