Boost logo

Boost Users :

From: Perry Smith (pedz_at_[hidden])
Date: 2006-02-16 10:43:12


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 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