If you overload a class' constructor and then use that new constructor, are derived classes then forced to define the new constructor as well?
With the default constructor, I could just do something like this, obviously.
Code:
class object1
{
public:
object1(void)
{
cout << "A new object has been created.\n";
}
};
class object2: public object1
{
};
Then, when you have a new object2, obviously it still outputs "A new object has been created." and you don't have to do anything about it if you want that.
However, if I do object1(int I) instead of object1(void), it does not seem to work the same way. My new object definitions are getting annoying to work with as I have to keep redefining the same constructors over and over the way I have it set up, and that will become a big problem if I want to create a lot of class types (such as a lot of types of item with my item class).
This is what I have currently.
Code:
class atom
{
public:
atom(){initialize();}
atom(int I){}
atom(atom *A)
{
A->entered(this);
}
};
class item: public atom
{
public:
item(void) : atom(0)
{ initialize();}
item(atom *A) : atom(A)
{ initialize();}
};
class test_item: public item
{
public:
test_item(void)
{ initialize();}
test_item(atom *A): item(A)
{initialize();}
};
If I take away the redefinitions of the constructor for test_item and try to create test_item by passing an atom pointer to it, such as the following
Code:
int main(int argc, char *argv[])
{
test_item I(locate(0,0,0));
//locate is a function that successfully returns another atom
//...
If I do that without having redefined the constructor overload, I get an error stating that there is no matching function call for using the constructor that way.
It works fine if I continually redefine the dang things all the time, but I was thinking that there must be a way to get them inherited so that I don't have to.