can local variables be changed in a const [member] function?

P

puzzlecracker

Ian said:
Does what? Please put your question in the body, not just the subject.

can local variables be changed in a const [member] function?


void doMeHard() const{

std::string request="do me";
request="do me hard";

}
 
I

int2str

puzzlecracker said:
can local variables be changed in a const [member] function?

Yes. Wouldn't make much sense if you couldn't, would it now ?!

Cheers,
Andre
 
J

Jim Langston

(Subject) can local variables be changed in a const [member] function?
does it only applies to member variables?

It only applies to member variables, not to variables declared inside the
function itself.
 
C

ctrucza

.... and it applies only to non-mutable member variables:

class MyClass
{
int a;
mutable int b;
void foo() const
{
a++; // this will not compile
b++; // this will work
}
};
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top