472,958 Members | 2,086 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

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


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.

Sep 6 '06 #1
3 2090
coala wrote:
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?
How is 'mPtr' declared?
Why could this work and why it can be compiled? We have used it for
years.
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
Sep 6 '06 #2
"coala" <qi*********@gmail.comwrote in message
news:11*********************@m73g2000cwd.googlegro ups.com...
:
: 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://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <http://www.brainbench.com
Sep 6 '06 #3
Yeah you guys are right, many thanks.

mPtr is mutable, I didn't notice that.

Sorry for that.
- C.
Victor Bazarov wrote:
coala wrote:
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?

How is 'mPtr' declared?
Why could this work and why it can be compiled? We have used it for
years.

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
Sep 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: July | last post by:
Hello! consider the following code: class A { public: virtual void f() const{ cout << "A::f()" << endl; } };
2
by: Rouben Rostamian | last post by:
The main() function in the following code defines an m by n matrix, assigns value(s) to its elements, then passes the matrix to function foo(). For whatever it's worth, I have declared foo() so...
1
by: coala | last post by:
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...
7
by: Luna Moon | last post by:
Hi all, I just couldn't get myself clear about the usage of "const" in front of and/or behind variables, pointers, classes, objects and functions... It's too confusing... any good clear...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.