问题标出了, A(); //不应该A::A()吗?
#include <iostream>
#include <string>
using namespace std;
class A
{
public:
A()
{
cout << "A constructor" << endl;
}
~A()
{
cout << "A destructor" << endl;
}
};
int main()
{
A(); //不应该A::A()吗?
cout<<"end xxx\n";
cout<<"end yyy\n";
}
The normal call should be
An analogy to a function that returns a value
You can call it like this
Of course you can also call it like this
Because this is a constructor. . . So this is equivalent to creating a temporary object. Why does the constructor have to write the class name twice