Reputation: 129
I am getting the error in the title, when I try to do the following.
class Test
{
private:
std::ifstream File;
public:
Test();
};
Test::Test() {}
I know there are many threads on stack about this issue. I know that I can resolve my issue by something as simple as
std::ifstream *File;
The reason I have posted this question is because my instructor has told me that I should be able to do this without modifying the first code block I posted. I've researched this, and I haven't found anything that suggests I can. Any ideas?
As requested.
class Test
{
private:
std::ifstream File;
public:
Test();
};
Test::Test() {}
int main()
{
Test test = Test();
return 0;
}
That is an example of something I can't compile.
Upvotes: 0
Views: 403
Reputation: 206577
The line
Test test = Test();
is a problem since std::ifstream
does not have a copy constructor or copy assignment operator. Use:
Test test;
If you have a C++11 compiler, you can also use:
Test test{};
Upvotes: 1