为什么我的fstream被隐式删除? [英] Why is my fstream being implicitly deleted?
问题描述
我正在使用一些HID设备,所有设备都有从以下基类派生的类(在 main.h 中):
I'm working with a few HID devices, all of which have classes deriving from the following base class (in main.h):
class HIDDevice {
public:
hid_device *device;
virtual void read(std::fstream)=0;
virtual void write(std::fstream)=0;
};
这是从中派生出来的设备类之一( device.h ) :
Here's one of the device classes deriving from it (device.h):
class MyDevice : public HIDDevice {
public:
void read(std::fstream);
void write(std::fstream);
};
...以及实施示例:
...and a sample of the implementation:
void MyDevice::read(std::fstream file) {
// Read from card and write to file
response = send_command(READ_DEVICE);
file.write((char *)&response[0], response.size());
}
...和来电者:
fstream file (filename, ios::binary | ios::in);
dev->read(file);
当我尝试编译时,我收到以下错误:
When I try and compile, I get the following error:
main.cpp:294:27:错误:使用已删除的函数'std :: basic_fstream :: basic_fstream(const std :: basic_fstream&)'
源自source / main.cpp的文件:24:0:
/usr/include/c++/4.6/fstream:761:11:错误:'std :: basic_fstream :: basic_fstream(const std :: basic_fstream& ')被隐式删除,因为默认定义不正确:
main.cpp:294:27: error: use of deleted function ‘std::basic_fstream::basic_fstream(const std::basic_fstream&)’
In file included from source/main.cpp:24:0: /usr/include/c++/4.6/fstream:761:11: error: ‘std::basic_fstream::basic_fstream(const std::basic_fstream&)’ is implicitly deleted because the default definition would be ill-formed:
...我不知道为什么,可能因为我对C ++很新,我做了一些愚蠢的事情。
... and I have no idea why, probably because I'm fairly new to C++ and I've done something idiotic.
将参数更改回引用(使用&),我收到以下错误:
Changing the arguments back to references (using &), I get the following error:
/main.o:(.rodata._ZTV13MyDevice [vtable for MyDevice] + 0x18):未定义引用`MyDevice :: write(std) :: basic_fstream>&)'
/main.o:(.rodata._ZTV13MyDevice[vtable for MyDevice]+0x18): undefined reference to `MyDevice::write(std::basic_fstream >&)'
任何人都可以帮我解决这个问题吗?
Can anyone help me fix this problem?
尝试通过引用抛弃那些 std :: fstream
。
Try tossing those std::fstream
s around by reference.
class MyDevice : public HIDDevice {
public:
void read(std::fstream&);
void write(std::fstream&);
};
这篇关于为什么我的fstream被隐式删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!