संभव डुप्लिकेट:
Why is it an error to use an empty set of brackets to call a constructor with no arguments?सी ++ डरावना निर्माता
चलें इस कोड
class Foo {
Foo(int) { }
};
फिर हम वहाँ परिणाम है:
int main() {
Foo f1 = Foo(5); // 1: OK, explicit call
Foo f2(5); // 2: OK, implicit call
Foo f3(); // 3: no error, "f3 is a non-class type Foo()", how so?
Foo f4(f1); // 4: OK, implicit call to default copy constructor
Foo f5; // 5: expected error: empty constructor missing
}
क्या आप बता सकते हैं कि के मामले में क्या हो रहा है?
खोज: vexing parse – Nim
@Nim: एक उत्तर होना चाहिए था। –
यह भी ध्यान दें कि उदाहरण 5 ऐसा करने के लिए अपेक्षित उदाहरण 3 कर रहा है और डिफ़ॉल्ट कन्स्ट्रक्टर को कॉल करता है। – Joe