const objects ->const member functions?

P

puzzlecracker

I am just curious: if you declare an object constant - can it call NOT
constant member functions of the class or only constant ones?


are there generic rules for such objects?


THANKs
 
N

Noah Roberts

puzzlecracker said:
I am just curious: if you declare an object constant - can it call NOT
constant member functions of the class or only constant ones?

I believe only const member functions may be called on a const object.
are there generic rules for such objects?

const objects are meant to be non-changing. A function that will not
alter the instance it is operating on should be labeled as const to
represent this fact. Member functions that do change the internals of
their instances must not be used on an object that is not supposed to
change.

It is pretty straight forward if you keep in mind what 'const' means.
It means 'constant'.

Hope that helps.
 
S

Siemel Naran

puzzlecracker said:
I am just curious: if you declare an object constant - can it call NOT
constant member functions of the class or only constant ones?

It can only call constant ones.
are there generic rules for such objects?

What do you mean?
 

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
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top