709394
10-23-2003, 01:15 PM
Is there a way to initialize LATER the constructor of the base class Pet in class Cat AFTER the Cat's constructor? Instead of the code below( Sample Code), I want something like this:
void Cat::Init(int iWeight, int iLegs)
{
something_Pet(iWeight);
m_iLegs = iLegs;
}
Sample Code
#include <iostream>
using std::cout;
using std::endl;
class Pet
{
protected:
int m_iWeight;
public:
Pet(int iWeight): m_iWeight(iWeight){};
};
class Cat: public Pet
{
private:
int m_iLegs;
public:
Cat(int iWeight, int iLegs)
:Pet(iWeight), m_iLegs(iLegs) // <---- Don't Want to initialize Pet() here BUT later.
{};
void Display(void){ cout<<m_iWeight<<endl; }
};
int main(void)
{
Cat CatName(3, 4);
CatName.Display();
return 0;
}
void Cat::Init(int iWeight, int iLegs)
{
something_Pet(iWeight);
m_iLegs = iLegs;
}
Sample Code
#include <iostream>
using std::cout;
using std::endl;
class Pet
{
protected:
int m_iWeight;
public:
Pet(int iWeight): m_iWeight(iWeight){};
};
class Cat: public Pet
{
private:
int m_iLegs;
public:
Cat(int iWeight, int iLegs)
:Pet(iWeight), m_iLegs(iLegs) // <---- Don't Want to initialize Pet() here BUT later.
{};
void Display(void){ cout<<m_iWeight<<endl; }
};
int main(void)
{
Cat CatName(3, 4);
CatName.Display();
return 0;
}