Search⌘ K
AI Features

const Return Types

Explore how const affects return types in C++ functions, including returning by value, reference, and pointer. Understand why making return values const can mislead and harm performance by preventing move operations, and learn best practices aligned with modern C++ standards.

A function can return values, references, and pointers, and all of these can be const. However, does it make sense to convert them to const? Let’s find out!

Returning const objects by value

The first-time const users might get enthusiastic about turning everything into const and might start converting signatures like std::string getName() into const std::string getName() const. ...