Should I return bool or const bool?

后端 未结 11 884
我在风中等你
我在风中等你 2021-01-01 10:36

Which is better:

bool MyClass::someQuery() const;

const bool MyClass::someQuery() const;

I\'ve been using \'const bool\' since I\'m sure I

11条回答
  •  天命终不由人
    2021-01-01 11:10

    This is an ancient post, but I think it's worth mentioning there is a potential corner case here since C++11. While, as stated by others, it will make no difference whether you use const bool or bool as return type in most cases, if you are using C++11 decltype and associates, e.g. result_of, you could declare a variable with the same type as the returning value of some function, and so the const would actually have an effect in this case.

提交回复
热议问题