我正在使用此库:https://github.com/Agamnentzar/bluetooth-serial-port
BTSerialPortBinding::Create(address, channelID)
Returns new instance of BTSerialPortBinding object
address: string containint bluetooth address of the device
channelID: ID of the serial port channel
我有一个声明:
unique_ptr<BTSerialPortBinding>bt(BTSerialPortBinding::Create(d1.address, 1));
当我将语句与ArduinoDevice.h中的声明分开并在构造函数中的ArduinoDevice.cpp中初始化时,如下所示:
std::unique_ptr<BTSerialPortBinding> bt;
bt.reset(BTSerialPortBinding::Create("93:83:, 1));
当我添加这些语句时,我收到以下错误:
ArduinoDevice &ArduinoDevice::operator =(const ArduinoDevice &)': attempting to reference a deleted function
Process.cpp文件中的相关位,由错误
引用dev = ArduinoDevice("/dev/tty.IP-DevB");
Process.h
#ifndef __PROCESS_H
#define __PROCESS_H
#define _USE_MATH_DEFINES
#include "ResonantLowpassFilter.h"
#include "ArduinoDevice.h"
//==============================================================================
/**
*/
class AudioProcessor : public AudioProcessor
{
public:
//==============================================================================
WahwahAudioProcessor();
~WahwahAudioProcessor();
void prepareToPlay (double sampleRate, int samplesPerBlock);
void releaseResources();
void processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages);
AudioProcessorEditor* createEditor();
int getNumParameters();
int getNumPrograms();
int getCurrentProgram();
void setCurrentProgram (int index);
const String getProgramName (int index);
void changeProgramName (int index, const String& newName);
float centreFrequency_, q_;
void updateFilterArduino();
ArduinoDevice dev; //instance to an Arduino device from which sensor data is read
};
#endif // _PROCESS
ArduinoDevice.h
#ifndef ArduinoDevice_h
#define ArduinoDevice_h
#include <stdio.h>
#include "BTSerialPortBinding.h"
#include <memory>
class ArduinoDevice
{
public:
ArduinoDevice(const char *dev="");
void connect();
void start(void);
void stop(void);
void read(void);
/**
Disconnects from Arduino device
**/
~ArduinoDevice();
private:
const char *device; //port address of the device (e.g. "/dev/tty.FireFly-E552-SPP")
std::unique_ptr<BTSerialPortBinding> bt; //bt serial port
void close(void);
};
#endif
编辑:
我使用的是Windows 10,Visual Studio 2015和Microsoft的C ++编译器。我还使用了一个额外的JUCE库(https://www.juce.com/)。
dev = ArduinoDevice("/dev/tty.IP-DevB"));
dev在Process.h文件中声明了它的ArduinoDevice实例
我的构造函数如下所示:
ArduinoDevice::ArduinoDevice(const char *dev)
{
device = dev;
bt.reset(BTSerialPortBinding::Create("98:D3:31:FD:11:1A", 1));
}
我现在在ArduinoDevice.cpp和声明.h中试过这个但是我仍然得到与上面相同的错误:
ArduinoDevice&&(const char *dev);
{
data = dev.data;
dev.data = nullptr;
}
答案 0 :(得分:0)
unique_ptr
不可复制。因此,当您将其声明为类的成员时,您的类也将变为不可复制的。错误确切地指出了这一点。 (因此删除了复制赋值运算符)。
请注意,通常编译器会自动为您生成移动赋值运算符。但是在您的情况下,因为您已经为类明确定义了析构函数,编译器无法为您安全地定义移动赋值运算符(或构造函数)。