P
Pingke
bool foo (T const & x,T const & y) const{
...
}
the third const means what?
thanks in advance!
...
}
the third const means what?
thanks in advance!
bool foo (T const & x,T const & y) const{
...
}
the third const means what?
thanks in advance!
Pingke said:bool foo (T const & x,T const & y) const{
...
}
the third const means what?
thanks in advance!
Frederick said:Pingke posted:
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 */
}
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.