同じメソッド名で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です:/var/folders/bg/171jl37d05v69c4t6t1tt03m0000gn/T//ccRJU6B9.oと/var/folders/bg/171jl37d05v69c4t6t1tt03m0000gn/T//ccVVSd1i.oアーキテクチャx86_64の場合、ld:duplicate symbol person :: getQuantity()が重複しています collect2:ldは1の終了ステータスを返しました
私はその特定のクラスの静的メソッドを作成します。どうすればそれを解決できますか?解決
二重アンダースコアを含む識別子は、実装のために予約されています。これはマクロ名にも当てはまります。 –
'using namespace std;'はヘッダーにも不正な形式です。 – Mat