私はプログラミングコースの演習を行ってきましたが、現在行っている特定の演習は、フレンド関数/メソッド/クラスに関するものです。私が抱えている問題は、友人機能が機能していないように見えることです。フレンド関数がアクセスできる変数にアクセスしようとしているコードの周りで、「[変数名] はこのコンテキスト内でプライベートです」というエラーが発生します。
ヘッダー ファイルのクラス定義は次のとおりです (スペースを節約するために不要なものを切り取っています)。
class Statistics {
private: // The personal data.
PersonalData person;
public:
Statistics();
Statistics(float weightKG, float heightM, char gender);
Statistics(PersonalData person);
virtual ~Statistics();
...
friend bool equalFunctionFriend(Statistics statOne, Statistics statTwo);
friend string trueOrFalseFriend(bool value);
};
エラーが表示されるメソッドは次のとおりです。
bool equalFuntionFriend(Statistics statOne, Statistics statTwo)
{
// Check the height.
if (statOne.person.heightM != statTwo.person.heightM)
return false;
// Check the weight.
if (statOne.person.weightKG != statTwo.person.weightKG)
return false;
// Check the gender.
if (statOne.person.gender != statTwo.person.gender)
return false;
// If the function hasn't returned false til now then all is well.
return true;
}
だから、私の質問は次のとおりです。私は何を間違っていますか?
編集: 問題は Angew によって解決されました。それはただのタイプミスだったようだ.非常に愚かな私 !