行ごとに見ていきましょう。
#ifndef PLAYER_H
#define PLAYER_H
#include "utility.h"
これまでのところ、コンパイラが をサポートしているかどうかを確認できます#pragma onceが、マクロは問題なく動作します。
class Player()
()はクラス名に使用できません。削除してください
{
public:
//getPlayerID();
};
#endif
ヘッダーファイルの残りの部分は問題ありません。実装ファイルを見てみましょう。
#include "player.h"
完全。プログラム全体で使用される定義が 1 つだけであることを確認するには、クラスをヘッダーに配置するのが最善の方法です。
class Player()
括弧は使用できませんが、ここでさらに大きな問題が発生します。その名前のクラスが既にあります。ヘッダーがクラス定義を提供するようにします。実装ファイルは、非インライン メンバー関数 (および任意のヘルパー コード) を提供するだけで済みます。
{
string playerID;
int timeCycle;
}
完全に修正されたバージョンは次のとおりです。
#if !defined(PLAYER_H)
#define PLAYER_H
#include <string>
#include "utility.h"
class Player
{
std::string player_id;
int time_cycle;
public:
// this is how you make a constructor, the parenthesis belong here, not on the class name
Player(std::string id, int time);
std::string getPlayerId() const;
};
#endif /* !defined(PLAYER_H) */
および実装ファイル
#include "player.h"
// and this is how you write a non-inline constructor
Player::Player(std::string id, int time)
: player_id(id)
, time_cycle(time)
{}
std::string Player::getPlayerId() const
{
return player_id;
}
これらの問題はすべて、本当に基本的な C++ の問題であり、NachOS とは関係ありません。