Following is a popular code:
class A
{
public:
static const string TYPE = "AEvent";
const string& getType() { return TYPE; }
};
Above code could be use like this:
if (aInstance.getType() == A::TYPE)
{
...
}
It's fine. But it's not intuitiveness. Did not? Look at the next code:
class A
{
public:
static const string& getType()
{
static const string TYPE = "AEvent";
return TYPE;
}
}
//Usage
if (aInstance.getType() == A::getType())
....
Of course, getType is static method but it's possible to access dot operator and It's more intuitively see to me.
How do you think about?