我正在尝试创建一个填充类对象的向量,类对象包含循环缓冲区作为其成员之一。我遇到了这个错误:
In file included from .pio/libdeps/teensy40/Vector/src/Vector.h:95:0,from src/main.cpp:2:
.pio/libdeps/teensy40/Vector/src/Vector/VectorDefinitions.h: In instantiation of 'void Vector<T>::push_back(const T&) [with T = Node]':
src/main.cpp:25:27: required from here
.pio/libdeps/teensy40/Vector/src/Vector/VectorDefinitions.h:162:22: error: use of deleted function 'Node& Node::operator=(const Node&)'
values_[size_++] = value;
^
src/main.cpp:5:7: note: 'Node& Node::operator=(const Node&)' is implicitly deleted because the default definition would be ill-formed:
class Node
^
src/main.cpp:5:7: error: use of deleted function 'CircularBuffer<T,S,IT>& CircularBuffer<T,IT>::operator=(const CircularBuffer<T,IT>&) [with T = long unsigned int; unsigned int S = 100u; IT = unsigned char]'
In file included from src/main.cpp:3:0:
.pio/libdeps/teensy40/CircularBuffer/CircularBuffer.h:64:18: note: declared here
CircularBuffer& operator=(const CircularBuffer&) = delete;
^
*** [.pio/build/teensy40/src/main.cpp.o] Error 1
======================================== [FAILED] Took 0.99 seconds ========================================
我创建了一个程序,它是我可以复制错误的最少代码:
#include <Arduino.h>
#include <Vector.h>
#include <CircularBuffer.h>
class Node
{
CircularBuffer<uint32_t,100> RTTSamplesBuffer;
};
// Vector to hold the nodes we currently have saved
Vector<Node> Nodes;
// This stuff is used in setup to make the vector not use dynamic allocation
// This version of the Vector library is special for arduino so it is not
// dynamically allocating the vector to prevent filling the controllers memory
const int NODE_COUNT_MAX = 20;
Node storage_array[NODE_COUNT_MAX];
void setup()
{
Serial.begin(115200);
// Point the vector to it's storage location.
Nodes.setStorage(storage_array);
while (!Serial)
;
// Create Node I want to add to the vector
Node testNode;
// Try and add the Node to the vector.
Nodes.push_back(testNode);
while (1)
;
}
void loop()
{
// put your main code here,to run repeatedly:
}
我使用 this 库作为向量,因为它与 Arduino 兼容并且不会填满内存,我使用 this 库作为循环缓冲区。谢谢!