Board index » cppbuilder » What is the meaning to use "const bool" as returned value

What is the meaning to use "const bool" as returned value


2005-10-22 04:51:21 AM
cppbuilder56
May someone explain me what is the reason to use the const reserved word at
the beginning of this following function?
/*****************************************************************/
/**
* \return bool - True if SIPMessageStore::_sessionInfo exists
*
* \brief Method used to verify if SIPMessageStore::_sessionInfo exists
*/
/*****************************************************************/
const bool SIPMessageStore::HasSessionInfo(void) const
{
if (_sessionInfo == NULL)
return false;
return true;
}
Thanks,
A. Fleury
 
 

Re:What is the meaning to use "const bool" as returned value

"A. Fleury" < XXXX@XXXXX.COM >writes:
Quote
May someone explain me what is the reason to use the const reserved word at
the beginning of this following function?
It's pretty much pointless. To the caller it makes no difference,
because it's an unnamed temporary anyway. The caller is either going
to use it in an expression or store it in a local variable. Were the
caller to take a reference to it, the only way that could be done is
through a "reference to const". So even if the function doesn't
explicitly return a const bool, the only case where it might matter is
already covered. Someone is just getting a little const-ambitious. ;)
Also:
Quote
const bool SIPMessageStore::HasSessionInfo(void) const
{
if (_sessionInfo == NULL)
return false;

return true;
}
... even though it's trivial, the function is still a bit "complex"
compared to what is required.
bool SIPMessageStore::HasSessionInfo(void) const
{
return _sessionInfo != NULL;
}
Needless ifs comparing a boolean expression to return a boolean
expression is one of my programming pet-peeves. With the value of the
condition we already have the result without any testing (though
possibly requiring a negation.)
--
Chris (TeamB);