|
From: Paul F. <pa...@fr...> - 2016-12-23 08:11:07
|
On 23 Dec 2016, at 04:04, Ivo Raisr wrote: > > > 2016-12-21 21:29 GMT+01:00 <pa...@fr...>: > > > It also tells the compiler where aggressive optimization is possible. > > > Unfortunately, mainly due to pointers/references and aliasing, this isn't as often as one might hope. > > For instance see > > http://www.gotw.ca/gotw/081.htm > > An interesting reading, indeed. > > Me being not a great C++ coder, would some please mind explaining the meaning of "const" here for this method: > char operator[]( size_t ) const; Hi Ivo If you have a class C with method f() like this class C { public: void f(); }; then in C++ f has an 'implicit this', which means that the actual code generated will be like void C::f(C* this). Since the 'this' pointer is implicit, there's no way to make it const in the formal parameter list, i.e., you can't write void C:f(C const* this). So in order to make the 'this' pointer const, the language allows putting const after the member declaration,, i.e., class C { public: void f() const; }; A+ Paul |