Return enum from a function : enum « Data Types « C++ Tutorial






#include <iostream>
 
 enum ERR_CODE { SUCCESS, ERROR };
 
 ERR_CODE f(int, int&, int&);
 
 int main()
 {
     int number = 2, squared, cubed;
     ERR_CODE result;
 
     result = f(number, squared, cubed);
 
     if (result == SUCCESS)
     {
         ;
     }
     else
         std::cout << "Error encountered!!\n";
     return 0;
 }
 
 ERR_CODE f(int n, int &rSquared, int &rCubed)
 {
         return ERROR;   // simple error code
 }
Error encountered!!








2.27.enum
2.27.1.Define and output an enumeration
2.27.2.A Demonstration of Enumerated Constants
2.27.3.Demonstrate an enumeration.
2.27.4.An enumeration variable
2.27.5.An enumeration static_cast
2.27.6.Return enum from a function
2.27.7.Using consts and enums in Arrays
2.27.8.Compare enum elements