我在课堂上需要一个矢量成员:
class A
{
private:
vector<ifstream> _files;
public:
bool addFile(const string& filePath);
};
bool A::addFile(const string& filePath)
{
ifstream ifile(filePath.c_str());
_files.push_back(ifile);//but errors;
}
如何通过成功编译完成此课程;
现在我的解决方案是使用矢量。这可以吗?或一些潜在的危险?
答案 0 :(得分:2)
STL容器需要元素 CopyConstructible 和可分配。 std::ifstream
不可复制。您需要使用指向std::ifstream
的智能指针。