const Object* obj;
The referenced object obj is considered constant and can’t be modified
void someMethod(const Object* obj) Proper way to call this?
const Object obj();
someMethod(&obj);
Object* obj = new Object(); someMethod(obj);
can const objects be passed by reference to non-const functions?
As there is no guarantee that the referenced object will not be modified when passed to a non-const parameter, the compiler blocks this.
call someMethod void someMethod(const string &str)
someMethod(string(“hellow world”));
Can const be applied to return values?
Yes, this will return it while blocking write access within the object.
benefits of void someMethod(conststring &str)
Since str is passed by reference here, the system doesn’t have to copy its value
This makes the program more efficient in terms of run-time and in terms of memory use