I’m trying to create 2 class with the same methods name.
Its an exercise, so i cant change the behavior.
Person.h
#ifndef __PERSON__
#define __PERSON__
#include <iostream>
using namespace std;
class person{
protected:
string name;
static int quantity;
private:
public:
person();
~person();
string getName() const;
static void add();
static int getQuantity();
};
#endif
person.cpp
#include "person.h"
int person::quantity=0;
person::person(){}
person::~person(){}
string person::getName() const{
return this->name;
}
int person::getQuantity(){
return person::quantity;
}
user.h
#ifndef __USER__
#define __USER__
#include <iostream>
#include "person.cpp"
using namespace std;
class user:public person{
private:
int age;
static int quantity;
public:
user();
~user();
static int getQuantity();
static void add();
int getAge();
void setAge(int age);
};
#endif
user.cpp
#include "user.h"
int user::quantity=0;
user::user():person(){}
user::~user(){}
int user::getQuantity(){
return user::quantity;
}
void user::add(){
user::quantity++;
}
int user::getAge(){
return this->age;
}
void user::setAge(int age){
if(age>=0)this->age=age;
}
the problem is ld: duplicate symbol person::getQuantity() in /var/folders/bg/171jl37d05v69c4t6t1tt03m0000gn/T//ccRJU6B9.o and /var/folders/bg/171jl37d05v69c4t6t1tt03m0000gn/T//ccVVSd1i.o for architecture x86_64
collect2: ld returned 1 exit status
but i create the static methods for that specific class. How can i solve that?
Solved… the problem was the #include “person.cpp”