description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid | ||
---|---|---|---|---|---|---|---|
Learn more about: Compiler Error C2534 |
Compiler Error C2534 |
11/04/2016 |
|
|
481f9f54-5b51-4aa0-8eea-218f10807705 |
'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.