"syang8" <sy****@gmail.com> wrote in message
news:11*********************@i39g2000cwa.googlegro ups.com...
In base class, I have a function "Initialize(int a)". In the derived
class , I need the funciton "Initialized" to do more things, therefore
I redefined the function as "Initialize(int a, int b)".
Now I want the Derived::initialize to include all the operations
contained in Base::initialize. Are there and simple ways to do that?
Currently, I just copy all the codes in Base::initialize to
Derived::initialize.
Initialization should occur in a constructor.
When a derived object is created, its constructor,
as well as the base's constructor will be
invoked automatically. (Base constructor is
called first).
class Base
{
public:
Base(int a)
{
/* etc */
}
};
class Derived : public Base
{
public:
Derived(int a, int b) : Base(a)
{
/* etc */
}
};
int main()
{
Derived d(42, 99); /* invokes Base::Base(42),
then Derived::Derived(42,99) */
return 0;
}
If the parameter 'a' for Derived() is not the same
value you want to pass to Base(), then add another
parameter to Derived() to pass to Base(), e.g.:
Derived(int b, int d1, int d2) : Base(b)
{
/* etc */
}
-Mike