You need to initialize it through the member-initializer list:
A::A(std::string filename) :
file(new std::ifstream(filename));
{ }
Your example was an attempt to call operator ()
on a unique_ptr
which is not possible.
Update: BTW, C++14 has std::make_unique
:
A::A(std::string filename) :
file(std::make_unique<std::ifstream>(filename));
{ }
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…