일부 숙제로 가장 이상한 오류가 발생합니다. 당신이 도울 수 있으면 좋겠다. 이 오류가 무엇입니까 :C++ 오버로드 추출 연산자 - 클래스에서 선언 된 전용 멤버에 오류가 액세스 할 수 없습니다.
Cannot access private member in class
주 : 나는 분명히이 글을 쓰는하지 오전하지만 난 가서 오류를 테스트하려고합니다. 당신이 가지고있는 모든 입력에 대해 고마워요!
// Amanda
// SoccerPlayer.cpp : main project file.
// October 6, 2012
/* a. Design a SoccerPlayer class that includes three integer fields: a player's jersey number,
number of goals, and number of assists. Overload extraction and insertion operators for the class.
b. Include an operation>() function for the class. One SoccerPlayer is considered greater
than another if the sum of goals plus assists is greater.
c. Create an array of 11 SoccerPlayers, then use the > operator to find the player who has the
greatest goals plus assists.*/
#include "stdafx.h"
#include<conio.h>
#include<iostream>
#include<string>
class SoccerPlayer
{
friend std::ostream operator<<(std::ostream, SoccerPlayer&);
// friend std::istream operator>>(std::istream, SoccerPlayer&);
private:
int jerseyNum;
int numGoals;
int numAssists;
public:
SoccerPlayer(int, int, int);
};
SoccerPlayer::SoccerPlayer(int jersey, int goal, int assist)
{
jerseyNum = jersey;
numGoals = goal;
numAssists = assist;
}
std::ostream operator<<(std::ostream player, SoccerPlayer& aPlayer)
{
player << "Jersey #" << aPlayer.jerseyNum <<
" Number of Goals " << aPlayer.numGoals <<
" Number of Assists " << aPlayer.numAssists;
return player ;
};
int main()
{
return 0;
}
정말 감사합니다. 나는이 장을 읽는데 어려움을 겪고있다. 정말 감사한다. –