Compiler Error C2561

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Compiler Error C2561.

identifier' : function must return a value

The function was declared as returning a value, but the function definition does not contain a return statement.

This error can be caused by an incorrect function prototype:

  1. If the function does not return a value, declare the function with return type void.

  2. Check that all possible branches of the function return a value of the type declared in the prototype.

  3. C++ functions containing inline assembly routines that store the return value in the AX register may need a return statement. Copy the value in AX to a temporary variable and return that variable from the function.

The following sample generates C2561:

// C2561.cpp  
int Test(int x) {  
   if (x) {  
      return;   // C2561  
      // try the following line instead  
      // return 1;  
   }  
   return 0;  
}  
  
int main() {  
   Test(1);  
}  

Show: