传递fstream作为结构成员

时间:2014-04-15 09:44:23

标签: c++ fstream

我有以下结构,

struct option
{   
    std::fstream fpointer;
    char* clifn;
};

我想将此结构作为参数传递给另一个函数(其他方式是将单个元素和fpointer作为引用传递),将其传递给函数会抛出编译器错误

error C2248: 'std::basic_fstream<_Elem,_Traits>::basic_fstream' : cannot access private member declared in class 'std::basic_fstream<_Elem,_Traits>'

有没有办法将struct member的std :: fstream对象传递给函数。

1 个答案:

答案 0 :(得分:6)

Streams are not copyable因此struct option不可复制,因为它有一个不可复制的成员(fpointer)。通过引用传递struct option以避免副本:

void some_function(option& a_option)
{
}
相关问题