Я пытаюсь создать 2 класса с одинаковыми именами методов.
Это упражнение, поэтому я не могу изменить поведение.
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;
}
проблема в том, что ld: дубликат символа person :: getQuantity () в /var/folders/bg/171jl37d05v69c4t6t1tt03m0000gn/T//ccRJU6B9.o и /var/folders/bg/171jl37d05v69c4t6t1tt03m00VV для архитектуры x86_64
collect2: ld вернул 1 статус выхода
но я создаю статические методы для этого конкретного класса. Как я могу решить это?