Estoy trabajando en algunas tareas y estoy recibiendo el error más extraño. Esperando que puedas ayudar. Estoy consiguiendo este error:C++ Operador de extracción de sobrecarga - Error no puede acceder al miembro privado declarado en la clase
Cannot access private member in class
Nota: Obviamente no he terminado de escribir esto, pero yo trato de poner a prueba de errores como voy. ¡Muchas gracias por cualquier aporte que tengas!
// 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;
}
Ya veo, ¡muchas gracias! Estoy teniendo dificultades con este capítulo, ¡realmente aprecio tu ayuda! –