Problem about //Constructor and //Destructor

Hello, Could someone have a look at //Constructor and //Destructor? There is a problem.
Thanks in advance

// Classes.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
// for cout
#include <vector>
// for vector
#include <string>
// for string
#include <fstream>
// for fileio
#include <cstdlib>
#include <time.h>

class Animal {
private:
int height;
int weight;
std::string name;

static int numOfAnimals;

public:
int getHeight() { return height; }
int getWeight() { return weight; }
std::string getName() { return name; }
void setHeight(int cm) { height = cm; }
void setWeight(int kg) { weight = kg; }
void setName(std::string animalName) { name = animalName; }
// Declaring a prototype
void setAll(int, int, std::string);
// Constructor
Animal(int, int, std::string);
// Destructor
~Animal();
// Constructor that doesn't receive anything
Animal();

static int getNumofAnimals() { return numOfAnimals; }

void toString();
};

int Animal::numOfAnimals = 0;

void Animal::setAll(int height, int weight, std::string name) {

this -> height = height;
this -> weight = weight;
this->name = name;
Animal::numOfAnimals++;
}

void::Animal::toString() {

std::cout << this -> name << " is " << this -> height << " cms tall and " << this->weight << " kgs in weight " << std::endl;

}

class Dog : public Animal {

private:
std::string sound = "Woof";

public:
void getSound() { std::cout << sound << std::endl; }

Dog(int, int, std::string, std::string);

Dog() : Animal() {};

void toString();

};

Dog::Dog(int height, int weight, std::string name, std::string bark) :
Animal(height, weight, name) {

this -> sound = bark;

};

void Dog::toString() {

std::cout << this->getName() << " is " << this->getHeight() << " cms tall and " << this->getWeight() << " kgs in weight and says " << this->sound << std::endl;
}

int main()
{
Animal fred;

fred.setHeight(33);
fred.setWeight(10);
fred.setName("Fred");

std::cout << fred.getName() << " is " << fred.getHeight() << " cms tall and " << fred.getWeight() << "kgs in weight" << std::endl;

Animal tom(36, 15, "Tom");

std::cout << tom.getName() << " is " << tom.getHeight() << " cms tall and " << tom.getWeight() << "kgs in weight" << std::endl;

Dog spot(38, 16, "Spot", "Woof");

std::cout << "Number of Animals" << Animal::getNumofAnimals() << std::endl;

spot.getSound();

tom.toString();
spot.toString();

spot.Animal::toString();

return 0;
}

Last edited on
Which constructor are we supposed to look at?
And what is the problem you're having?

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.

I get the following linker errors:
1
2
3
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall Animal::~Animal(void)" (??1Animal@@QAE@XZ) referenced in function __unwindfunclet$??0Dog@@QAE@HHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z$0
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall Animal::Animal(int,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0Animal@@QAE@HHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: __thiscall Dog::Dog(int,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0Dog@@QAE@HHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z)
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall Animal::Animal(void)" (??0Animal@@QAE@XZ) referenced in function _main

1 - You never implemented your Animal destructor.
2 - You never implemented you explicit Animal constructor.
3 - You never implemented you Animal default constructor.

Last edited on
Sorry, I'm new to this. And thanks a lot
Topic archived. No new replies allowed.