const . - ( ).
, , const , , const, - . , , non-const, , const.
, const ( ), .
:
#include <iostream>
using std::cout;
class Foo
{
public:
bool Happy;
Foo(): Happy(false)
{
}
void Method() const
{
}
void Method()
{
Happy = true;
}
};
int main()
{
Foo A;
const Foo B;
A.Method();
cout << A.Happy << '\n';
B.Method();
cout << B.Happy << '\n';
return 0;
}
:
1
0
Press any key to continue . . .