0

我在初始化此类时遇到问题:

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

像这样尝试:

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

谁能指出我如何做到这一点的正确方向?另外,初始化后,我可以通过说类似的话来更改引用吗

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

提前致谢

4

1 回答 1

0

您还没有声明构造函数,只定义了它。
声明构造函数并将其设置为 public:

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

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

int main()
{
    Player p;
}

我可以更改参考吗?

不,您不能更改引用,只能更改所引用内容的值。

于 2015-06-27T23:38:33.773 回答