我对这段代码有疑问:
#include <fstream>
struct A
{
A(std::ifstream input)
{
//some actions
}
};
int main()
{
std::ifstream input("somefile.xxx");
while (input.good())
{
A(input);
}
return 0;
}
G ++输出我这个:
$ g++ file.cpp
file.cpp: In function `int main()':
file.cpp:17: error: no matching function for call to `A::A()'
file.cpp:4: note: candidates are: A::A(const A&)
file.cpp:6: note: A::A(std::ifstream)
将其更改为此后,它会编译(但这并不能解决问题):
#include <fstream>
struct A
{
A(int a)
{
//some actions
}
};
int main()
{
std::ifstream input("dane.dat");
while (input.good())
{
A(5);
}
return 0;
}
有人可以解释我出了什么问题以及如何解决吗?谢谢。