<we*****@yahoo.comwrote in message
news:11*********************@k70g2000cwa.googlegro ups.com...
Hi,
I like to use a const pointer to a shm inside a class, and I don't want
to instantiate it through class ctor, is there any other way around?
The main purpose for const pointer is to avoid somebody accidently
re-assign the pointer to something else in realtime.
Who are you protecting it from? Other code in the same class? Code in
other classes? Other programmers?
If you're talking about protecting it from code outside the class, you could
just make it private instead of const. You can add a public "getter"
function (returning a const pointer) for code that might need to use the
pointer from outside the class.
If the initialization of that pointer also needs to be made from code
outside the class, then you can also make a public "setter" function. In
that function, only allocate the new object for that pointer if the pointer
is NULL. (Naturally, this means setting the pointer to NULL in the
constructor.)
If that's not what you're talking about, you'll need to explain further.
-Howard