const function

R

Radde

Hello,
In const member function, does this pointer is constant, or this
is pointing to const object..How do i check this??

Cheers...
 
A

Alf P. Steinbach

* Radde:
In const member function, does this pointer is constant,

In modern C++ 'this' is always a constant pointer value: you cannot
assign to 'this'.

or this is pointing to const object.
Yes.


How do i check this??

If you mean, how do you check what the rules are: any good C++ book,
or the standard.

If you mean, how can you check in code whether '*this' (note the
dereferencing) is constant, there's seldom any need for that: in a
'const' member function it's constant, otherwise not.

Note that you cannot check in a constructor or destructor whether the
object being constructed/destroyed is declared 'const' or not, without
providing that information yourself.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,296
Messages
2,571,535
Members
48,281
Latest member
DaneLxa72

Latest Threads

Top