Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) return type

 

The return type of a function denotes the data type it returns.

 

For example, the function below, ToInt, returns an int, so its return type is int.

 

#include <string>

///ToInt converts a std::string to an integer
///From http://www.richelbilderbeek.nl/CppToInt.htm
const int ToInt(const std::string& s)
{
  return std::atoi(s.c_str());
}

 

 

 

 

 

Advice

 

 

 

 

 

 

References

 

  1. Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 12.7. Advice. page 341: '[4] Don't return pointers or references to local variables'
  2. Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 18.5. Advice. page 547: '[4] For large results, use a move constructor'

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict