Hi,
I'm starting to get the hang of this inheritance thing, but I'm completely thrown off by the order of which initialization events take place. I'm wondering if I'm missing something blatantly obvious! Here is an example of something that is completely different than I expected. Suppose I have a couple of classes:
class D: public B
{
D(C _c):B(_c),e(_c.e)
{
_c.b*=2.0;//somehow before getting passed to old B constructor
cerr<<"D's "<<a<<"="<<b*c*d*e;
}
string a;
double b;
double c;
double d;
double e;
};
Is there some way to do that type of thing?
I mean, I have two questions really. I seem to always end up having inherited constructors called *before* my new constructor code when I want to have the old constructor code called after my new constructor section. Can the old constructor get called after new code? If so, how? Also, I seem to be having trouble passing inherited classes into inherited classes as illustrated above--at least I haven't got that type of thing to work. Is this possible, and if so, how?
Thanks,
Sean
Ok, if Base classes are *always* constructed before derived classes, is there then no way to use the principles of inheritance if all that needs to be inherited is everything at the ends of a program? Maybe I'm missing something, but it seems to throw away what I thought was the whole point of re-usability of code if there is no way to call an already written constructor after newly added code. I'm so confused suddenly. Is this ruining the whole language for everyone else too? Or if not, what am I missing?
Base classes have to be initialized first. The theory is that the derived object, being a "base plus stuff", needs to have
the "lower level" stuff initialized first. Sort of like having to build the first floor of the building before building the
second floor.