Friday, February 23, 2007

C++ - const Keyword

Use the keyword const to signify (to developers, not just the compiler) that a variable does not change).

/**
* This method doesn't change its object
* @param[in] obj Reference to a constant MyObj
* @return A constant reference to obj
*/
const MyObj& MyObj::myMethod(const MyObj &obj) const
{
return obj;
}

No comments: