ifstream作为函数的参数要加&

    技术2022-05-20  28

    void foo(ifstream ifs) {} // 编译出错

    void foo(ifstream& ifs) {} // 编译成功

    原因:stream不能被复制

    实现方法:

    Make the copy constructor and assignment operator private (like inthe "ios" example - remember members are private by default if youdeclare your class with "class"). If you write any constructors youdon't get the implicit default constructor, so make sure you write at least one accessible constructor or you won't be able to create any objects of this class.RegardsBuster


    最新回复(0)