by nnq · 13y ago · 0 comments
The function in example 1 is modifying a member variable, and there is indeed a keyword that requires functions not to modify the class they operate on: const. It's very powerful, and by a long shot my favourite feature of C++.
That said, the function in question actually has to modify a member variable.
int square (int) __attribute__ ((pure));
But I can't say how smart is the compiler in handling those attributes.[1] http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
http://llvm.org/docs/LangRef.html#function-attributes
https://github.com/llvm-mirror/llvm/blob/master/lib/Transfor...