// sample of Operator Overloading
#include <string>
class PlMessageHeader
{
std::string m_ThreadSender;
std::string m_ThreadReceiver;
//return true if the messages are equal, false otherwise
inlinebooloperator == (const PlMessageHeader &b) const
{
return ( (b.m_ThreadSender==m_ThreadSender) &&
(b.m_ThreadReceiver==m_ThreadReceiver) );
}
//return true if the message is for name
inlinebool isFor (const std::string &name) const
{
return (m_ThreadReceiver==name);
}
//return true if the message is for name
inlinebool isFor (constchar *name) const
{
return (m_ThreadReceiver==name);// since name type is std::string, it becomes unsafe if name == NULL
}
};
now i know what the code does but i'm confused by the const at the end of the overload operator declaration and function declaration and cant seem to understand why the argument inside the overload operator and function declaration is a constant, cant it be just as it is without const ? (i know what const does but cant understand why its needed where it is in the sample code + i know that functions inside of the class are declared as inline by the compiler and it is unneeded to declare them as inline like in the sample).