B
Brian Genisio
Hi all,
Please note the following code... Why is it that when you call the
child with the a constructor that has arguments, the parent constructor
gets called as default? How do I tell the Child(int) constructor to use
the Father(int) constructor?
My results are:
Father default constructor
Child Arg Constructor
//
// Sample Code:
//
#include <iostream.h>
// The parent class
class Father
{
public:
Father(int newX) : x(newX)
{ cout << "Father Arg Constructor" << endl; }
Father() : x(0)
{ cout << "Father default constructor" << endl;}
private:
int x;
};
// The child class, that inherits from the parent class
class Child : public Father
{
public:
Child(int newX)
{ cout << "Child Arg Constructor" << endl;}
};
int main(void)
{
Child xyz(4);
return 0;
}
Please note the following code... Why is it that when you call the
child with the a constructor that has arguments, the parent constructor
gets called as default? How do I tell the Child(int) constructor to use
the Father(int) constructor?
My results are:
Father default constructor
Child Arg Constructor
//
// Sample Code:
//
#include <iostream.h>
// The parent class
class Father
{
public:
Father(int newX) : x(newX)
{ cout << "Father Arg Constructor" << endl; }
Father() : x(0)
{ cout << "Father default constructor" << endl;}
private:
int x;
};
// The child class, that inherits from the parent class
class Child : public Father
{
public:
Child(int newX)
{ cout << "Child Arg Constructor" << endl;}
};
int main(void)
{
Child xyz(4);
return 0;
}