Smart Pointer release() const : it can set the pointer to null with the keyword "const"?

Smart Pointer release() const : it can set the pointer to null with the keyword "const"?

Post by coal » Thu, 07 Sep 2006 20:46:14



In Smart Pointer class, we have a piece of code:

inline void release(void) const { if (mPtr) mPtr->release(); mPtr = 0;
}

It can set mPtr but it is still const?

Why could this work and why it can be compiled? We have used it for
years.

- C.
 
 
 

Smart Pointer release() const : it can set the pointer to null with the keyword "const"?

Post by Victor Baz » Thu, 07 Sep 2006 21:40:15


How is 'mPtr' declared?


You've used it for years and haven't looked at the declaration? Post
the complete program distilled from your "Smart Pointer class", with
the declaration of 'mPtr' (I presume it's a data member) visible, then
we can talk.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

 
 
 

Smart Pointer release() const : it can set the pointer to null with the keyword "const"?

Post by Ivan Vecer » Thu, 07 Sep 2006 22:41:26


:
: In Smart Pointer class, we have a piece of code:
:
: inline void release(void) const { if (mPtr) mPtr->release(); mPtr = 0;
: }
:
: It can set mPtr but it is still const?
If mPtr is a data member, this will only compile if mPtr
has been declared as mutable:
T* mutable mPtr;


Ivan
--
http://www.yqcomputer.com/ ;- email contact form
Brainbench MVP for C++ <> http://www.yqcomputer.com/