I have started learning C++ yesterday and have knowledge in Java, C# and mostly C. I was trying to learn inheritance and constructors so I set up two new classes, Animal which is base class for Cat (delivered class) and Location which is setup in Cat class, both have the same constructor in syntax, different values, but my visual studio code and gcc can't figure out why am I inputting three integers into constructor of Location and I can't find answer for this online, sorry if it is dumb question and very easy to solve but I'm stuck and don't know what to do. Both Animal and Location files are headers (.h).
Main class:
#include<iostream>
#include"thisClass.h"
#include"LocationHeader.h"
using namespace std;
class Cat : public Animal {
private:
Location location(0, 0, 0);
public:
Cat(int numOfLegs, string newName) : Animal(numOfLegs, newName){}
void meow() {
cout << "Meow!" << endl;
}
Location getLocation() {
return location;
}
};
int main() {
Cat cat(4, "Cat");
cat.meow();
cout << cat.getName() << endl;
cout << cat.getLocation().getX() << endl;
return 0;
}
Animal class:
#include<iostream>
class Animal {
int legs;
std::string name;
public:
Animal(int numOfLegs, std::string newName) {
legs = numOfLegs;
name = newName;
}
void setNumOfLegs(int numOfLegs) {
legs = numOfLegs;
}
void setName(std::string newName) {
name = newName;
}
int getNumOfLegs() {
return legs;
}
std::string getName() {
return name;
}
~Animal() {}
};
Location class:
#include<iostream>
class Location {
int x, y, z;
public:
Location(int newX, int newY, int newZ) {
x = newX;
y = newY;
z = newZ;
}
void setX(int newX) {
x = newX;
}
void setY(int newY) {
y = newY;
}
void setZ(int newZ) {
z = newZ;
}
int getX() {
return x;
}
int getY() {
return y;
}
int getZ() {
return z;
}
~Location() {}
};