...

...
Last edited on
1
2
3
4
5
6
7
8
9
10
11
AnimalNode.hpp

#include "Animal.hpp"

class AnimalNode {
private:
	Vehicle& vehicle;
public:
	Vehicle& getAnimal() const;
	virtual ~AnimalNode();
};


Other than the fact that your program is actually about vehicles, but you change the terminology to animals so that your teacher would not see that you are asking for help here...

And you try to return &Animal in the getAnimal() function which is meaningless (return the address of a class name which is never seen anywhere?)...

The getAnimal() function is declared const. That means that the function cannot modify the object or provide the caller the capability of modifying the object. Because you are returning a (non-const) reference to to a data member, the caller could change the value of the data member at any time.

To fix, this, simply return a const Animal&. That way the caller cannot modify the reference that is returned, and the object can safely remain const.

Now, please don't post partially modified code that may or may not present the problem that you are seeing. If you need to obfuscate the code that you are really writing, prepare a minimal version of your code and try to compile it to make sure that it gives the errors you are asking about. The code snippets you provided in your initial post aren't even close.

Topic archived. No new replies allowed.