I remembered, from university, that const method can not changes fields. I am returning to C++ now, and I have written simple program.
#include "stdafx.h"
#include <iostream>
using namespace std;
class Box
{
int a;
int b;
int square;
public:
Box(int a, int b)
{
this->a = a;
this->b = b;
}
const void showSquare(void) const
{
cout << this->a * this->b << endl;
}
const void setDim(int a, int b)
{
this->a = a;
this->b = b;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Box b(2, 4);
b.showSquare();
b.setDim(2, 5);
b.showSquare();
int a;
cin >> a;
return 0;
}
In my case const method can change fields of class? How is it possible?
Than you in advance.