Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   can a constructor inherited (http://www.go4expert.com/forums/constructor-inherited-t6219/)

Jaya 6Sep2007 06:03

can a constructor inherited
 
can a constructor inherited

shabbir 6Sep2007 09:51

Re: can a constructor inherited
 
Quote:

Originally Posted by Jaya
can a constructor inherited

Can you frame the question correctly? I don't understand what you meant by constructor being inherited? Do you mean to say syntactically or semantically.

DaWei 6Sep2007 11:27

Re: can a constructor inherited
 
Can a bear shitted?

Jaya 6Sep2007 11:57

Re: can a constructor inherited
 
Can a constructor of a class be inherited ? can u please explain in detail

shabbir 6Sep2007 15:23

Re: can a constructor inherited
 
Quote:

Originally Posted by Jaya
Can a constructor of a class be inherited ? can u please explain in detail

If you don't read the response don't expect any thing more than what you see in replies as thread.

DaWei 6Sep2007 20:37

Re: can a constructor inherited
 
Consider testing your hypotheses or resolving your questions by writing a small piece of code and checking the outcome. It's a good learning method.
Code:

#include<iostream>
using std::cout;
using std::endl;

class parent
{
public:
    int x;
    parent ()
    {
        cout << "\tThis is the parent constructor" << endl;
        x = 0;
    }
};

class child: public parent
{
public:
    int x;
};

class sibling: public parent
{
public:
    int x;
    sibling ()
    {
        cout << "\tThis is the sibling constructor" << endl;
        x = 2;
    }
};
int main()
{
    cout << "Instantiating the child" << endl;
    child theKid;
    cout << "Instantiating the sibling" << endl;;
    sibling theBro;
    theKid.x = 4;
    cout << "Child x = " << theKid.x << endl;
    cout << "Sibling x = " << theBro.x << endl;
    return 0;
}

Quote:

Originally Posted by The output
Code:

Instantiating the child
        This is the parent constructor
Instantiating the sibling
        This is the parent constructor
        This is the sibling constructor
Child x = 4
Sibling x = 2




All times are GMT +5.5. The time now is 15:23.