Pingke posted:
bool foo (T const & x,T const & y) const{
...
}
the third const means what?
thanks in advance!
This is a member function, and it belongs within a class.
By placing "const" after a member function's name, you indicate that the
function can be invoked on a const object of the class. By default, no
member function can be invoked on a const object of a class, so you have
to explicitly enable this functionality by writing "const" after the
function signature.
class ArbitraryClass {
public:
void ConstFunc() const {}
void NonConstFunc() {}
};
int main()
{
ArbitraryClass obj1;
obj1.ConstFunc(); /* No problem */
obj1.NonConstFunc(); /* No problem */
ArbitraryClass const obj2;
obj2.ConstFunc(); /* No problem */
obj2.NonConstFunc(); /* COMPILE ERROR */
}
--
Frederick Gotham