3
I need to create a base class animal and 3 other hereditary classes of other animals. Each class must have its own function emitirSom. They should be invoked polymorphically through a vector. I don’t know if the constructor was done right. Type, the constructor must be made in the base class or the hereditary classes?
Error messages:
main.cpp(15): error C2661: 'dog::dog': no overloaded function takes 2 arguments
main.cpp(16): error C2661: 'cow::cow': no overloaded function takes 2 arguments
main.cpp(17): error C2661: 'cat::cat': no overloaded function takes 2 arguments
Header. h
#include <string>
using namespace std;
class animal
{
protected:
    string nome;
    int idade;
public:
    animal(const string &nome_, int idade_);
    virtual void emitirSom() const = 0;
};
class cachorro : public animal
{
public:
    virtual void emitirSom() const;
};
class vaca : public animal
{
    virtual void emitirSom() const;
};
class gato: public animal
{
    virtual void emitirSom() const;
};
Implmentation.cpp
#include "stdafx.h"
#include "header.h"
#include <iostream>
#include <string>
using namespace std;
animal::animal(const string &nome_, int idade_)
{
    nome = nome_;
    idade = -idade_;
}
void cachorro::emitirSom() const
{
    cout << "\n" << nome << "latindo: Aauauauauau";
}
void gato::emitirSom() const
{
    cout << "\n" << nome << "miando: MiauMiau";
}
void vaca::emitirSom() const
{
    cout << "\n" << nome << "mugindo: Muuuuuuu";
}
Main.cpp
#include "stdafx.h"
#include "header.h"
#include <vector>
void fazerBarulho(const animal* const &bicho)
{
    bicho->emitirSom();
}
int main()
{
    cachorro toby("Toby", 8);
    vaca lili("Lili",29);
    gato satanas("Satanas",3);
    vector < animal * > zoo( 3 );
    zoo[0] = &toby;
    zoo[1] = &lili;
    zoo[2] = &satanas;
    for (size_t i = 0; i < zoo.size(); ++i)
        fazerBarulho(zoo[0]);
#if WIN32
    system("PAUSE");
#endif
}
						
Does the image have a purpose? It looks horribly rendered next to the question in the mobile version of the site
– Jefferson Quesado
It’s the error screen. Pera I’ll copy the text
– Rafael
Related: https://answall.com/q/73530/64969
– Jefferson Quesado
now reading the error message I managed to understand your doubt, +1
– Jefferson Quesado