Skip to content

Latest commit

 

History

History
36 lines (29 loc) · 1.05 KB

compiler-error-c2534.md

File metadata and controls

36 lines (29 loc) · 1.05 KB
description title ms.date f1_keywords helpviewer_keywords ms.assetid
Learn more about: Compiler Error C2534
Compiler Error C2534
11/04/2016
C2534
C2534
481f9f54-5b51-4aa0-8eea-218f10807705

Compiler Error C2534

'identifier' : constructor cannot return a value

A constructor cannot contain a return statement with an expression (even if the expression has type void). This differs from regular void-returning function where a return expression of type void is allowed. However, using the return statement without an expression is allowed for early returns in the constructor.

The following sample generates C2534:

// C2534.cpp
// compile with: /c
void void_func() {}

class A {
public:
   int i;
   A() {
      return i;   // C2534
      return 123;   // C2534
      return (void)0;   // C2534
      return void_func();   // C2534

      return;   // OK
   }
};

The preceding errors may be fixed by removing the entire return statement or omitting the return expression if an early return is desired.