I’m relatively new to C++. I was looking into the source code of Box2D to learn how professional people manage their code and found this kind of pairs quite a lot:
inline b2Body* b2World::GetBodyList()
{
return m_bodyList;
}
inline const b2Body* b2World::GetBodyList() const
{
return m_bodyList;
}
Questions that popped into my mind is, how do we know which function that we called? What’s the reasoning for this kind of pair?
The non-
constversion cannot be called on aconst b2World; note that the return types of the methods are different. Try runningSee also the C++ FAQ Lite on
const-correctness.