I am trying to do an inheritance problem. I have a base class Animal with parameters int height, age, and weight. I also have a default constructor and a constructor with parameters. I have a derived class Dog with the parameter dogType and a constructor with the parameters from Animal and the new parameter, dogType. My question is, how do I use the constructor w/ parameters from Animal for the Dog class? This is how I tried to do it, however, it is not working. I will include all the header and implementation files. Any help is greatly appreciated!
#pragma once
#include <iostream>
#include <string>
class Animal
{
private:
int height;
int age;
int weight;
public:
Animal();
Animal(int h, int a, int w);
void print()const;
};
#include "Animal.h"
#include <iostream>
Animal::Animal()
{
height = 0;
age = 0;
weight = 0;
}
Animal::Animal(int h, int a, int w)
{
height = h;
age = a;
weight = w;
}
void Animal::print()const
{
std::cout << "Height:" << height << std::endl;
std::cout << "Age:" << age << std::endl;
std::cout << "Weight:" << weight << std::endl;
}
#pragma once
#include "Animal.h"
#include <iostream>
class Dog :
public Animal
{
private:
std::string dogType;
public:
Dog();
Dog(int h, int a, int w, std::string dt);
void print()const;
};
#include "Dog.h"
Dog::Dog()
{
}
Dog::Dog(int h, int a, int w, std::string dt)
{
Animal::Animal(h, a, w);
dogType = dt;
}
void Dog::print()const
{
Animal::print();
std::cout << "Dog Type:" << dogType << std::endl;
}
g++ -Wall -Wextra -g. See also GDB