0

I'm having problems initializing this class:

class Player{
  ///
  std::istream ∈
  ///
};

Trying like this:

Player::Player():in(cin){
  ///
}

Can anyone point me in the right direction of how to accomplish this? Also, after initialization, can I change the reference by saying something like

stringstream ss("test");
Player p;
p.in = ss;

thanks in advance

  • 1
    You can only initialize references and you can't change them later. The most you can do is assign new values to what is being referenced, but not the reference itself. – aslg Jun 27 '15 at 23:36

1 Answers1

0

You haven't declared the constructor, only defined it.
Declare the constructor and set it public:

class Player{
public:
  Player(); // You need to declare the constructor
  std::istream ∈
};

Player::Player():in(cin)
{}

int main()
{
    Player p;
}

can I change the reference?

No, you can't change the reference, only values to what is being referenced.

Andreas DM
  • 10,685
  • 6
  • 35
  • 62