c++ question
To understand what are const functions we have to know and understand const objects. Let's say we have class:
class foo{
int x;
public:
foo(int arg): x(arg){}
int y;
};
In main function we write so we create const object initialized with vaue 2:
const foo f(2);
At this point we should ask oureslves what that means?
Well it means that we tell compiler that this object will be constant so none of it's component's during object live will be changed. Well there are no problem for compiler with public members with that all of them will become constant let's say we can now write:
std::cout<<f.y;
but of course:
f.y 3;//This will cause an error
And now if our class will look le't say like this:
class foo{
int x;
public:
foo(int arg): x(arg){}
void f(int arg){}
int y;
carmel hotel roomscarmel motelscarmel vacation rentals