Device.cpp 파일에 현재 생성자가 있습니다.
Device::Device(const char *devName)
{
device = devName;
bt.reset(BTSerialPortBinding::Create(devName, 1));
}
My Device.h에는 다음과 같은 클래스 Device가 있습니다.
Device(const char *devName="");
~Device();
const char *device;
std::unique_ptr<BTSerialPortBinding> bt;
이동 생성자를 오른쪽으로 옮기고 unique_ptr은 복사 할 수 없기 때문에 할당을 이동하여 클래스를 복사 할 수 없게되고 ~ Device ()가이를 삭제합니다.
따라서 내가 사용하려고 할 때 :
Device dev; // declared in Process.h
dev = Device("93:11:22"); // initialised in Process.cpp
다음과 같은 오류가 발생합니다.
Device &Device::operator =(const Device &)': attempting to reference a deleted function
나는 Device.h에서 운없이 다음을 시도했습니다.
//move assignment operator
Device &operator=(Device &&o)
{
if (this != &o)
{
bt = std::move(o.bt);
}
return *this;
}
Device(Device &&o) : bt(std::move(o.bt)) {};
이것을 시도하면 다음과 같은 오류가 발생합니다.
1>bluetoothserialport.lib(BTSerialPortBinding.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MTd_StaticDebug' in ArduinoDevice.obj
1>bluetoothserialport.lib(BluetoothHelpers.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MTd_StaticDebug' in ArduinoDevice.obj
1>msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: __thiscall std::_Lockit::_Lockit(int)" (??0_Lockit@std@@QAE@H@Z) already defined in libcpmtd.lib(xlock.obj)
1>msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: __thiscall std::_Lockit::~_Lockit(void)" (??1_Lockit@std@@QAE@XZ) already defined in libcpmtd.lib(xlock.obj)
1>msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "void __cdecl std::_Debug_message(wchar_t const *,wchar_t const *,unsigned int)" (?_Debug_message@std@@YAXPB_W0I@Z) already defined in libcpmtd.lib(stdthrow.obj)
1>msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "void __cdecl std::_Xbad_alloc(void)" (?_Xbad_alloc@std@@YAXXZ) already defined in libcpmtd.lib(xthrow.obj)
1>msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "void __cdecl std::_Xlength_error(char const *)" (?_Xlength_error@std@@YAXPBD@Z) already defined in libcpmtd.lib(xthrow.obj)
1>msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "void __cdecl std::_Xout_of_range(char const *)" (?_Xout_of_range@std@@YAXPBD@Z) already defined in libcpmtd.lib(xthrow.obj)
Visual Studio 2015의 Windows 10에서 실행, BTSerialPortBinding에이 라이브러리 사용 : https://github.com/Agamnentzar/bluetooth-serial-port
unique_ptr
복사 할 수 없으며이를 포함하는 클래스는 복사 구성 또는 복사 할당이 불가능합니다. 클래스에 대해 최소한 이동 생성자와 이동 할당 연산자를 정의해야합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다