-3
#include <iostream>
using namespace std;
class A{
public:
    A(){cout << "A()" << endl; }
    A(string s): str(s){ cout << "A(" << str << ")" << endl; }
    ~A(){ cout << "delete!" << endl;}
    string str = "000";
};
int main(int argc, char** argv)
{
    //A a0;    // it will call A() by default
    A a1();    //even if i comment A(), the compiler will no warn me anything
    A a2("123");
    cout << a2.x << endl;
    return 0;
}

output:

A(123)
123
delete!

so, i just want to know why "A a1();" can't works? can someone helps me ? thank you!

1 Answers1

3

A a1(); is a function prototype, taking no parameters and returning an A

Bathsheba
  • 231,907
  • 34
  • 361
  • 483