【问题标题】:How to define the prototyp for a method which expect istream如何为期望 istream 的方法定义原型
【发布时间】:2015-09-16 09:57:10
【问题描述】:

我有以下代码:

int readInt(istream &stream)
{
    int i;
    stream >> i;
    return i;
}

谁能告诉我如何声明这个方法的原型,我可以在我的 main() 之后复制代码。我试过int readInt(istream),但这似乎不起作用。

【问题讨论】:

  • 错误信息是什么? (请注意,您的代码缺少标头包含和 std 命名空间)
  • 包含命名空间。一秒钟我必须翻译错误信息。
  • 只复制定义:int readInt(istream &stream);(或int readInt(istream &);)。参数类型是istream & - 引用istream - 不是istream
  • 智能感知:多个重载函数实例匹配参数列表:Function "readInt(std::istream); Function "readInt(std::istream &stream);
  • @molbdnilo 解决了这个问题,但我真的不明白为什么.. :D

标签: c++ methods


【解决方案1】:

您忘记了原型参数列表中的引用。应该是:int readInt(istream &);

【讨论】:

    猜你喜欢
    • 2015-01-08
    • 1970-01-01
    • 1970-01-01
    • 2011-11-17
    • 2011-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多