|
-
September 5th, 2010, 07:33 AM
#1
can't understand const function's output
Hi.
Please tell me what will be the correct output for this code:
class A {
public:
int & _i;
A();
void foo() const;
};
A::A(int& i) : _i(i) { ... }
void A::foo() const {
_i++;
}
With this main:
int main() {
int i = 5;
const A a (i);
std::cout << a._i << std::endl;
a.foo();
std::cout << a._i << std::endl;
}
Can _i be changed? Isn't it the meaning of const func - that
all class' members can't be changed by it ?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|