नोट
इस पृष्ठ तक पहुंच के लिए प्राधिकरण की आवश्यकता होती है। आप साइन इन करने या निर्देशिकाएँ बदलने का प्रयास कर सकते हैं।
इस पृष्ठ तक पहुंच के लिए प्राधिकरण की आवश्यकता होती है। आप निर्देशिकाएँ बदलने का प्रयास कर सकते हैं।
'identifier' : constructor cannot return a value
Remarks
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.
Example
The following example 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.