Skip to content

Commit 8432983

Browse files
authored
Update C2534
1 parent c192538 commit 8432983

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

docs/error-messages/compiler-errors-2/compiler-error-c2534.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,29 @@ ms.assetid: 481f9f54-5b51-4aa0-8eea-218f10807705
1010

1111
'identifier' : constructor cannot return a value
1212

13-
A constructor cannot return a value or have a return type (not even a **`void`** return type).
13+
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.
1414

15-
This error may be fixed by removing the **`return`** statement from the constructor definition.
15+
## Example
1616

1717
The following sample generates C2534:
1818

1919
```cpp
2020
// C2534.cpp
21+
// compile with: /c
22+
void void_func() {}
23+
2124
class A {
2225
public:
2326
int i;
24-
A() { return i; } // C2534
27+
A() {
28+
return i; // C2534
29+
return 123; // C2534
30+
return (void)0; // C2534
31+
return void_func(); // C2534
32+
33+
return; // OK
34+
}
2535
};
2636
```
37+
38+
The preceding errors may be fixed by removing the entire **`return`** statement or omitting the return expression if an early return is desired.

0 commit comments

Comments
 (0)