|
Boost Users : |
From: RIVASSEAU Jean Noel (JN.RIVASSEAU_at_[hidden])
Date: 2006-02-16 11:12:09
I admit I did not really take the time to read your whole post, but I think you just want to do:
static const uint64_t mask = 0x12345678; // note the "static"
Also, this is not a Boost related question!! I think you should ask this kind of questions on C++ forums or IRC channels.
Regards
Jean-Noël
-----Message d'origine-----
De : boost-users-bounces_at_[hidden] [mailto:boost-users-bounces_at_[hidden]] De la part de Perry Smith
Envoyé : jeudi 16 février 2006 16:43
À : boost-users_at_[hidden]
Objet : [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