c++ compiler error cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'

后端 未结 4 2023
执笔经年
执笔经年 2020-12-22 11:38

Hey Im getting an error I think has to do with copying ofstream variable from reading other posts and Ive tried to change

std::ofstream outfil;
4条回答
  •  一整个雨季
    2020-12-22 11:59

    void PrintValues(const std::string& title, std::vector>& v, std::ofstream outfil) takes a std::ofstream by value, that is, copying the actual argument you pass to it, but fstreams may not be copied, hence the error you get regarding the private base it has.

    You got it right when you thought of references as a solution, but you missed the point where you should use it. The correct way to solve your problem is to take a std::ofstream by reference in PrintValues, to do that, simply change its declaration to the following

    Your guess is correct, `void PrintValues(const std::string& title, std::vector>& v, std::ofstream& outfil)
    

提交回复
热议问题