H
heng
#include<iostream>
#include<string>
using namespace std;
class A
{
public:
int x;
int y;
A(int y_){y=y_;}
};
int main()
{
A aobj;
return 0;
}
When I define an object, some data members cannot be initialized and no
appropriate default constructor is available. So, there is an error.
However, even if I add the default constructor explicitly, there are
still errors in the following code.
#include<iostream>
#include<string>
using namespace std;
class A
{
public:
int x;
int y;
A();
A(int y_){y=y_;}
};
int main()
{
A aobj;
return 0;
}
Why?
#include<string>
using namespace std;
class A
{
public:
int x;
int y;
A(int y_){y=y_;}
};
int main()
{
A aobj;
return 0;
}
When I define an object, some data members cannot be initialized and no
appropriate default constructor is available. So, there is an error.
However, even if I add the default constructor explicitly, there are
still errors in the following code.
#include<iostream>
#include<string>
using namespace std;
class A
{
public:
int x;
int y;
A();
A(int y_){y=y_;}
};
int main()
{
A aobj;
return 0;
}
Why?