4 ms·
Just don't fall into the trap of believing that only making constness transitive would make it fool-proof. A non-"pure" const member function with const parame
by Findecanor 4y ago
Just don't fall into the trap of believing that only making constness transitive would make it fool-proof.
A non-"pure" const member function with const parameters could still call some other function with access to a "mutable" alias to what you have a const reference to.
You would need something more, such as an ownership system to make the compiler make that impossible (as in Rust) or to detect it (the topic of Master's thesis, BTW ) ... but then it would no longer be something resembling C++.
- compiler-devel 4y agoGenerally speaking a const member function can't call a member function that is non-const or a member function that modifies a member variable that's not declared mutable. If the present const member function has a const reference to something that's marked mutable, then it's effectively a no-op as far as const value qualifications are concerned.