1

On removing the constructor line the error dissapears.

Dog::Dog(std::string name, double height, double weight, std::string sound) : Animal(name, height, weight) {
    this -> sound = sound;
}


void Dog::ToString() {
    //std::cout << this->name << " is " << this->height << " cm's tall and " << this->weight << " kg's in weight" << std::endl;
    //cannot do the line above as it is private, if it were to be protected we could call it. "sharing with childs of class"

    std::cout << GetName() << " is " << GetHeight() << " cm's tall and " << GetWeight() << " kg's in weight" << std::endl;
}

enter image description here

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


    static int numOfAnimals;
    static bool canTalk;

public:
    std::string GetName() {
        return name;
    }

    double GetHeight() {
        return height;
    }

    double GetWeight() {
        return weight;
    }

    void SetName(std::string name) {
        this->name = name;
    }

    void SetHeight(double height) {
        this->height = height; //height that is passed in through parameter becomes the height
    }
    void SetWeight(double weight) {
        this->weight = weight;
    }

    void SetAll(std::string, double, double); 

    Animal(std::string, double, double); //constructor
    Animal(); //for when no parameters are passed
    ~Animal(); //destructor

    static int GetNumOfAnimals() {
        return numOfAnimals;
    }
    void ToString();
};

code and constructor of animal class as requested by @inisheer

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
Stanley
  • 2,434
  • 18
  • 28
  • 1
    Post the constructor for your Animal class. – Inisheer Jul 05 '19 at 03:06
  • 2
    The shown image is unintelligible, and unreadable. Please include all information in your question ***as plain text***. – Sam Varshavchik Jul 05 '19 at 03:08
  • 3
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Borgleader Jul 05 '19 at 03:09
  • 1
    added full animal class @Inisheer – Stanley Jul 05 '19 at 03:11
  • 2
    @Stanley that should be included in your question (especially since you claimed to have added "the full animal class"). I dont see this definition in there. We cant diagnose the issue if parts of the code are missing (especially an error complaining about *parts of code not being there*) – Borgleader Jul 05 '19 at 03:15
  • 3
    Please use plain text in any future edits and in your future posts; images are not as usable or accessible to users who might benefit from screen readers, special fonts, or other assistive technologies, and aren't as useful as text-format code that we can interact with as text. Images are great for sharing screenshots and visual data relevant to a question, but they unfortunately aren't great containers for code, that we might need to copy-paste, test locally, etc. – nanofarad Jul 05 '19 at 03:19
  • @Borgleader i see, i totally misunderstood and i thank you for taking a look at my question both you and andrey akhmetov were correct. Sorry for the incompetency but again thank you for your help, both of you! – Stanley Jul 05 '19 at 03:19
  • @AndreyAkhmetov I will take that into concidereation and i will use a codesnippet website next time, I just felt that in this instance with this amount of code a screenshot would be simpler. again, thank you for your help! – Stanley Jul 05 '19 at 03:20
  • 1
    @Stanley There shouldn't be a compelling reason to use an external website at all. Stack Overflow has, by design, the ability to share appropriately-sized snippets of code directly in one's post. Questions need to serve the asker and future visitors alike, and having external resources that could undergo link-rot or disappear at any time does not assist with that goal. – nanofarad Jul 05 '19 at 03:21

1 Answers1

4

You've declared the constructor:

Animal(std::string, double, double); //constructor

However, you did not define it, which is the important part here. When the Dog constructor is compiled, a reference is made to Animal::Animal(std::string, double, double), which the linker tries and fails to resolve. In your follow-up comment, you still haven't defined this particular constructor.

You need to actually define the Animal constructor and destructor appropriately, e.g.

Animal(std::string name, double height, double weight) : name(name), height(height), weight(weight) {}

Unrelated: There is a potential rule-of-three violation lurking here, which you should be more aware of once you start to interact with resources that require specific management. You've defined a destructor, but not a copy constructor or copy assignment operator. In your case this is fine because the dtor doesn't do anything interesting aside from a print side effect, but you should strive to follow this guideline to avoid future troubles.

nanofarad
  • 40,330
  • 4
  • 86
  • 117