From my testing, an object can still be modified after creation.
//Let's use this copy constructor as an example:
Foo::Foo( const Foo& F )
{
var = F.var;
}
//With this code:
Foo f1;
const Foo f2(f1); //No Error?
There is no initializtion list, so f2 is being modified after it was created. So if the members of Foo are still modifiable, what is being made constant?
f2is not being modified after being created. This linecreates
f2, andf2can modify it’s own data members in the body of the constructor. Once the body of the constructor is exited, the object is fully constructed and cannot be modified.There are a couple of points worth mentioning:
varwereconst, then you would have to initialize it in the constructor’s initialization list, and it could not be modified in the body of the constructor. This is independent of whether you have aconstFooinstance or not.varwere declaredmutable, then it would be possible to modify aconst Fooinstance via aconstmethod that modifiesvar.