C++ const in getter [duplicate]

There is a huge difference between the two ways.

const bool isReady()

The code above will return a const bool, but it does not guarantee that the object will not change its logic state.

bool isReady() const

This will return a bool, and it guarantees that the logic state of your object will not change. In this case it is not necessary to write const in front of the return type. It makes no sense to return a const bool because it is a copy anyway. So making it const is useless. The second const is needed for const correctness, which is not used for speed reasons but to make your program more reliable and safe.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)