【发布时间】:2013-10-14 18:09:18
【问题描述】:
A.hpp:
class A {
private:
std::unique_ptr<std::ifstream> file;
public:
A(std::string filename);
};
A.cpp:
A::A(std::string filename) {
this->file(new std::ifstream(filename.c_str()));
}
我得到的错误被抛出:
A.cpp:7:43: error: no match for call to ‘(std::unique_ptr<std::basic_ifstream<char> >) (std::ifstream*)’
有没有人知道为什么会发生这种情况?我已经尝试了许多不同的方法来让它工作,但都无济于事。
【问题讨论】:
标签: c++ smart-pointers ifstream unique-ptr