class A
{
A() : empty{false}
{
}
bool is_empty() const
{
return empty;
}
void fill()
{
// Here's my question
// if(is_empty())
// or
// if(empty)
}
private:
bool empty;
};
Is it better to check the value of a member variable directly or call a member function that returns the value?
In my opinion calling a member function will definitely be more expensive than checking it directly, but on the other hand you can change the logic of A::is_empty() without affecting the other member functions that rely on that logic.