#include <iostream>
using namespace std;
class IAnimal
{
protected:
int m_Age;
double m_Weight;
public:
int Get_Age() const {return m_Age;}
void Set_Age(int age) {m_Age = age;}
double Get_Weight() const {return m_Weight;}
void Set_Weight(double weight) {m_Weight = weight;}
virtual void Move() = 0;
//=============================
IAnimal() {m_Age = m_Weight = 0;}
IAnimal(int age, double weight) {m_Age = age; m_Weight = weight;}
virtual ~IAnimal(){};
};
class CBird : public IAnimal
{
public:
void Move() {cout << "JA LATAM !!!\n";}
CBird(int age, double weight) {m_Age = age; m_Weight = weight;}
};
class CDog : public IAnimal
{
public:
CDog(int age, double weight) {m_Age = age; m_Weight = weight;}
void Move() {cout << "JA BIEGAM !!!\n";}
};
int main()
{
IAnimal * p_animal = new CDog(5, 5.0);
p_animal->Move();
cout << p_animal->Get_Age() << endl;;
cout << p_animal->Get_Weight() << endl;
delete p_animal;
}
Mam takie pytanie, czy jest możliwość żeby podczas tworzenia obiektu klasy CDog lub CBird użyć konstruktora z parametrami z klasy bazowej IAnimal
zamiast tworzenia w nich osobnych konstruktorów? Jeśli tak to w jaki sposób.
Pozdrawiam :)