issue with simple inheritance

Why doesn't this work????

#include <iostream>
using namespace std;

class xyz{
int x;
public:
xyz(int y)
{
x=y;
cout<<"c: x = "<<x<<endl;
}
void hello()
{
cout<<"hello"<<endl;
}
~xyz()
{
cout<<"d: x = "<<x<<endl;
}
};
class abc:public xyz
{
public:
};
int main()
{
abc p;
p.hello();
return 0;
}

Since it has been mentioned http://www.cplusplus.com/doc/tutorial/classes/ that if constructor is not mentioned explicitly, then the compiler creates a default constructor.

excerpts from the tutorial... But the compiler not only creates a default constructor for you if you do not specify your own. It provides three special member functions in total that are implicitly declared if you do not declare your own. These are the copy constructor, the copy assignment operator, and the default destructor.

The aforementioned example with class inheritance works well if we simply change the parameterized constructor to a default one or even if we removed it.

Kindly, suggest.
The point is this:
But the compiler not only creates a default constructor for you if you do not specify your own.

You did specify your own in class xyz. So the compiler doesn't create one for you. And that constructor must be satisfied
To expound further, the compiler cannot generate a default constructor for abc, because the constructor so generated would need to call a constructor with the same signature on the base class, and xyz doesn't have a constructor that takes no arguments.
Topic archived. No new replies allowed.