|
Boost Users : |
From: Matt Davies (matt.davies_at_[hidden])
Date: 2006-02-16 11:22:57
I don't think it is the appropriate place.
You need to make it static as well to be in the class:
static const uint64_t mask = 0x12345678
Cheers,
Matt Davies
Rockstar Leeds
-----Original Message-----
From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Perry Smith
Sent: 16 February 2006 15:43
To: boost-users_at_[hidden]
Subject: [Boost-users] Non-boost c++ novice help
If this is not an appropriate list for this question, please let me
know.
The books tell me to prefer const to #defines -- but where do you put
them to have the right scope and not take up space in the object?
What I'd like to have is:
class register {
void set_mask() { reg |= mask; }
private:
uint64_t reg;
const uint64_t mask = 0x12345678;
};
But the compiler will not let me do this and even if it did,the mask
would take up physical space. I don't want mask (or reg) to be
visable outside of the class and I want the compiler to use mask as a
compile time constant that does not consume space after the compile.
I vaguely know about namespace but if I put this inside a namespace,
then I have to do:
namespace hardware {
const mask = 0x12345678;
class register {
void set_mask() { reg |= mask; }
private:
uint64_t reg;
};
};
// .. define a register
hardware::register doddy;
and "mask" is not really private -- just obscured. I can still do:
int i = hardware::mask;
This just feels like I've taken a wrong turn somewhere. How would
this be "properly" done?
Thanks,
Perry
_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net