Hi, I am not sure if this is the right forum If this isn’t I apologize in advance. But I was having some trouble with cling when it comes to using classes and static variables. look at the following example
class Animal{
private:
int height;
int weight;
string name;
// Static variables are variables that are shared by all the objects of a class.
static int numOfAnimals;
public:
// static int numOfAnimals;
int getHeight(){ return height; }
int getWeight(){ return weight; }
string getName(){ return name; }
void setHeight(int cm){
height = cm;
return;}
void setWeight(int kg){
weight = kg;
return;}
void setName(string animalName){
name = animalName;
return;}
void setAll(int, int, string);
Animal(int, int, string);
~Animal();
Animal();
static int getNumOfAnimals(){ return numOfAnimals; }
void toString();
};
int Animal::numOfAnimals = 0;
e[1minput_line_15:2:14: e[0me[0;1;31merror: e[0me[1mdefinition or redeclaration of 'numOfAnimals' not allowed inside a
functione[0m
int Animal::numOfAnimals = 0;
e[0;1;32m ~~~~~~~~^
e[0m
Interpreter Error: