I am trying to run my code for this coding exercise and I am getting this error: undefined reference to BumbleBee::BumbleBee()
, undefined reference to GrassHopper::GrassHopper()
I'm practicing inheritance and I am using the Insect class as a base class to Inherit functions and methods, but I don't understand what I am doing wrong. Any help is appreciated, here is the code:
#include <iostream>
using namespace std;
// Insect class declaration
class Insect
{
protected:
int antennae;
int legs;
int eyes;
public:
// default constructor
Insect();
// getters
int getAntennae() const;
int getLegs() const;
int getEyes() const;
};
// BumbleBee class declaration
class BumbleBee : public Insect
{
public:
BumbleBee();
void sting()
{ cout << "STING!" << endl; }
};
// GrassHopper class declaration
class GrassHopper : public Insect
{
public:
GrassHopper();
void hop()
{ cout << "HOP!" << endl; }
};
// main
int main()
{
BumbleBee *bumblePtr = new BumbleBee;
GrassHopper *hopperPtr = new GrassHopper;
cout << "A bumble bee has " << bumblePtr->getLegs() << " legs and can ";
bumblePtr->sting();
cout << endl;
cout << "A grass hopper has " << hopperPtr->getLegs() << " legs and can ";
hopperPtr->hop();
delete bumblePtr;
bumblePtr = nullptr;
delete hopperPtr;
hopperPtr = nullptr;
return 0;
}
// member function definitions
Insect::Insect()
{
antennae = 2;
eyes = 2;
legs = 6;
}
int Insect::getAntennae() const
{ return antennae; }
int Insect::getLegs() const
{ return legs; }
int Insect::getEyes() const
{ return eyes; }
//Desired output
/*
A bumble bee has 6 legs and can sting!
A grass hopper has 6 legs and can hop!
*/